Angularjs is very beautiful, so that a lot of young people and my uncle, its beauty is not only in the writing, but also in the design approach to perfection, with what services injected into what services, so the method is very intuitive, the programmer feels intuitive, the program in the run up as needed to load, This load-on-demand is much better than the full load mode, both in terms of performance and expressiveness.
Ajax Loading Data
$http Service provides a set of Ajax methods to load data, get,post are supported, and $http services are dynamically loaded in angular, called di or IOC in object-oriented
Angular.module ('todoapp', []). Controller ('realdatacontroller' , function ($http, $scope) { varthis; $http. Get ('/soa/getmenus'). Success (function (data) { = data; }). Error (function (data, status, headers, config) {});
The above is a way to load the $http service and use the HTTP service, and the following is a way to use it with an alias, and the code is more streamlined.
Angular.module ('Todoapp', []). Controller ('RealDataController2', ["$http","$scope", function ($h, $s) {varSelf = This; $h.Get('/soa/getmenus'). Success (function (data) {self.datalist=data; }). Error (Function (data, status, headers, config) {}); }]);
With the program above, we can bind the data to HTML elements.
<DivNg-controller= "Realdatacontroller as real"> <ul> <Ling-repeat= "Item in Real.datalist"> <span>{Item.} MenuID}}</span> <span>{Item.} MenuName}}</span> <span>{Item.} Updatedate | Date: ' Yyyy-mm-dd HH:mm:ss Z '}}</span> <span><ahref= "javascript:void (0)"Ng-click= "Real.edit ()">Edit</a></span>| <span><ahref= "javascript:void (0)"Ng-click= "Real.del (item)">Delete</a></span> </Li> </ul> </Div>
The results are as follows
It is noteworthy that for the "delete" operation, this example has also been implemented, it is divided into two aspects, a foreground user experience display, the second is the background data deletion, the foreground uses angular's two-way binding technology, the elements of the array object is deleted, the background through the $ Http.post call the corresponding API to delete the real data, the code is as follows
// Delete function (o) { 1); // Ajax request Background API clears real data $http. Post ("/soa/delmenu?id=" + o.menuid); }
After using angular for a few days, it feels like it's a bit similar to Knockoutjs, and of course, it's enhanced in function, which is beyond doubt!
angularjs~ Integrated AJAX and service injection