javascript - How to load more content with Angular (JSON) -


i'm newbie on angularjs, , now, i'm trying create simplest web-app, load json data server.
works fine now, looks this:

js file

app.controller('mycont', ['$scope', '$http', function($scope, $http) {     $scope.moreitems = function() {         $http.post('php/index.php').             success(function (data) {                 $scope.posts = data;             }         );          console.log('button work');     } }]); 

html

<div ng-controller="mycont">       <span ng-click="moreitems()">load more</span>       <ul>         <li ng-repeat="some in something">{{some.here}}</li>     </ul> </div> 

php generates json page. every time gives me different data. trouble have no idea how load more data controller. replaces it, want concat it.

you can use angular.extend concatenate data. whenever json data retrieved, concatenated previous data in same json object.

note: if new incoming data consisting same properties of previous json object override new data. sure incoming data consists different properties if want store old data of properties.

app.controller('mycont', ['$scope', '$http', function($scope, $http) {      $scope.moreitems = function()     {         $http.post('php/index.php').             success(function (data)                  {                                            angular.extend($scope.posts, data)                 }         );          console.log('button work');     } }]); 

additional info: if want store previous data of properties can use browser local storage add , retrive data. save making multiple db call.

adding data :

localstorageservice.add("postsdata", json.stringify($scope.posts));  

retriveing data :

$scope.posts = localstorageservice.get("postsdata"); 

for more info on browserlocalstorage let me know......


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -