data binding - Callback function to $apply() in angularjs? -
What I want to do is push an object into an array in which the angle is the angle binding, then a click function The newly created element code is such that
$ scope.fruits = {"orange", "plum", "cherry"}; $ Scope.add = function () {$ scope.fruits.push ("apple"); // This will add an element to html, then I want to click on element $ ('# fruits'). Children.eq (-1) .click (); // Click on the last element (which has been created now)}
is HTML:
The problem is, when an object is pushed onto the model, then angular can do something like a $. $ Dynamically () applies to updates html if I click on the last element. children (). Eq (-1). Click (), it will not wait after the new element is created, which actually clicks "cherry" div.
I tried to call $ claims. () Is implemented before clicking ($), it works, but I found this error message:
$ is already in progress
Which I believe is not a good practice, and $ applicable () should not be said in this way.
When you add to the $ scope, you are within the digestive loop and do not compile the DOM And until those loops are not completed - basically you change the array in your $ radius, but in that moment there is still the last item in the Dome. Once this loop is released, then Repeaters will fire and render new DOM elements to the monitor, but you already have your own Controller has left
The solution is really simple After the current digest loop ends you need to queue your updates. You can use setTimeout without any delay. And will call it during current processing:
setTimeout (function () {$ ('# fruits'). Children (). Eq (-1)). Click ();}, 0);
This is working:
(I strongly encourage you to avoid directing the dom from within your controller when writing a instructions for it. To encourage)
Comments
Post a Comment