Before I show you how to programmatically update / update model data from the server? I have to explain the concept of data binding to you. This is an extremely powerful concept that truly revolutionizes the way you evolve. Perhaps you should read this concept from this or this seconde link in order not to understand how AngularjS works.
Now I will show you an example that exaplain how you can update your model from the server.
HTML code:
<div ng-controller="PersonListCtrl"> <ul> <li ng-repeat="person in persons"> Name: {{person.name}}, Age {{person.age}} </li> </ul> <button ng-click="updateData()">Refresh Data</button> </div>
So, our controller is named: PersonListCtrl and our model is named: . go to the js controller to develop a function called: updateData() that will be called when we need to update and update our face model.
Javascript Code:
app.controller('adsController', function($log,$scope,...){ ..... $scope.updateData = function(){ $http.get('/persons').success(function(data) { $scope.persons = data;
Now I will explain to you how it works: when the user clicks the Update Data button, the server will call the updateData () function, and inside this function we will call our web service with the $http.get() function and when we get the result from our ws , we will touch it in our model (line X). Determine what affects the results for our model, our view of this list will be changed using the new data.
Mohamed Amine BERGUIGA May 31 '15 at 16:52 2015-05-31 16:52
source share