Reputation: 3
I'm using a button that invokes clickLoadMorePosts which has two parameters, the important one is the date, this button triggers the function below.
In the response, I'm receiving javascript code that update this date in the button's parameter and it's updating fine, but when I click again that button, the scope is taking the first date, instead the date i got in the response even when this new date is updated in the html code (I looked through Google chrome inspector).
I think the problem is because $scope is not updating the new content and therefore is not taking the new date.
I also read that I should probably use $apply in some place, but I got an error because $http uses $apply.
Help and insight are appreciated!
HTML
<span id="loadMorePosts" ng-click="clickLoadMorePosts({{$idAccount}},'{{$date}}')"> Load more content </span>
JAVASCRIPT
function TodoCtrl($scope, $http ) {
$scope.clickLoadMorePosts = function(idAccount, date) {
$http.post("loadPersonalPosts", {'idAccount': idAccount, 'date': date} )
.success(function (data) {
$('#postLoader').append(data);
}).error(function (data) {
alert("error");
});
};
}
Upvotes: 0
Views: 56
Reputation: 8623
You should assign the response data to a scope variable, in the page, you should use like {$scope.data. date} rather than manipulating the DOM via append.
Upvotes: 2