1

I'm playing around with AngularJS (and trying to get my head round it) and have a controller which for the purpose of this question can be simplified to:

$scope.addMessage = function() {
      $scope.messages.push({author: 'nick', 
        text: $scope.messageText, active: true});
};

Every time that the model changes due to this '$scope.addMessage' I want to run emojify.run();... If I simply put it after $scope.messages.push... it runs before the data is shown in the view and therefore doesn't work. How do I call the function emojify.run(); once the view has updated?

1
  • 2
    I suspect that there is a better way to do what you are attempting. AngularJS to my knowledge does not support this type of pattern. Are you trying to change something in the DOM after the data updates? If so, look into directives. Having your controller manipulate the DOM directly seems to violate the MVC principles that AngularJS is meant to be used with. Commented Jun 1, 2013 at 17:55

1 Answer 1

1

I think you need to use the scope.$watch listener on your model

See this tutorial that does something similar: http://www.youtube.com/watch?v=8ozyXwLzFYs

$watch is called in the $digest phase. For details see the Scope lifecycle here: http://docs.angularjs.org/guide/scope

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.