So this is the last post related to AngularJS in LxD Series in today I am covering one of the most basic aspect of SPAs that is, interacting with backend systems. Angular comes with $http object that does something what many of us have been doing with $post/$get/$ajax methods of jQuery. Let’s jump into the code. So far we were using a predefined array having data of our records. It was something like this: ngAddressBook.controller('ngAddressListController', ['$scope', function ($scope) { $scope.contacts = [ {id:1,first_name:'Jane', last_name:'Doe','Phone':'123-456789','Email':'jane@example.com'}, {id:2,first_name:'Jhon', last_name:'Doe','Phone':'123-456789','Email':'jhon@example.com'} ]; $scope.getTotalContacts = function () { return $scope.contacts.length; }; }]); Which will now be changed to this: ngAddressBook.controller('ngAddressListController', function ($scope,$http) { $http.get('api.php').success(function(data) { $scope.contacts…
-
-
LxD Series: Implementing AngularJS templates and routers
Ok so we are going to implement templates and routers in AngularJS. Routers are going to help us to get unique URLs per page, or view while templates, as you know will help to provide theme of our app. This is what we came up in my last post. What I am going to do to shift the markup of this listing in a separate file and come up with a layout. Therefore index.html will look like this: <!doctype html> <html ng-app="ngAddressBook"> <head> <title>Ng Addressbook</title> <link href="main.css" rel="stylesheet" media="screen" /> </head> <body> <div ng-controller="ngAddressListController"> <div id="container"> <h1>Ng Address Book</h1> <div id="content" ng-view> </div> </div> </div> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.1/angular.min.js"></script> <script src = "angular-route.min.js"></script>…
-
LxD Series: Starting AngularJS
I am making this post after 20 days. I got busy as there was a new addition in my family. I am father of two sons now, thanks to God Almighty. Anyways, only a week is left in January. I will try to cover as much as I can so that we can have a minimal idea about AngularJS and it’s working so that we can start using it in our future projects. Running first program Ok So we are now going to run our first program but before that we need to setup AngularJS. If you visit AngularJS, you will see you can configure it in multiple ways(CDN,Download,Bower and npm).…