I am new to angularjs and trying my hands on a an application. I am trying to create load more feature and stuck with .push() to the scope element.
How to push posts in following data to a $scope variable? Please check the code in controller below.
{
"status": 200,
"result": {
"success": true,
"message": [
{
"offset": 6,
"load_more": true,
"brand_name": "HARLEY DAVIDSON",
"posts": [
{
"postID": 41,
"post_title": "DYNA STREET BOB (FD2) (FXDB)",
"engine_size": "1584 ccm",
"year": "2007-2013"
},
{
"postID": 43,
"post_title": "DYNA FAT BOB (FXDF)",
"engine_size": "1584 ccm ",
"year": "2008-2012"
},
{
"postID": 46,
"post_title": "Bike 1",
"engine_size": "1584 ccm ",
"year": "2008-2012"
},
{
"postID": 47,
"post_title": "Bike 2",
"engine_size": "1584 ccm ",
"year": "2008-2012"
},
{
"postID": 48,
"post_title": "Bike 3",
"engine_size": "1584 ccm ",
"year": "2008-2012"
},
{
"postID": 49,
"post_title": "Bike 4",
"engine_size": "1584 ccm ",
"year": "2008-2012"
}
]
}
]
},
"timestamp": 1396896763
}
Here's the code in controller:
$scope.bikes = [];
Restangular.all('bikes/getBikesByTermId/' + $stateParams.termID+'/'+$scope.offset).getList().then(function (data) {
$scope.term_title = data[0].brand_name;
$scope.bikes = data[0].posts;
$scope.offset = data[0].offset;
$scope.load_more = data[0].load_more;
$scope.isLoading = 0;
});
$scope.loadMore = function(){
Restangular.all('bikes/getBikesByTermId/' + $stateParams.termID+'/'+$scope.offset).getList().then(function (data) {
$scope.term_title = data[0].brand_name;
$scope.bikes.push(data[0].posts);
$scope.offset = data[0].offset;
$scope.load_more = data[0].load_more;
$scope.isLoading = 0;
});
};