0

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");
      });
    };
}
1
  • You're appending the data to $('#postLoader')... what is that? Commented Apr 1, 2015 at 6:34

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.