Saturday 15 September 2012

angularjs - Anyway to trigger a method when Angular is done adding scope updates to the DOM? -


I see a way to execute the code when I add changes to the $ diameter variable, in this case $ scope the result is. I need to do this to call some legacy code for which it is necessary to keep the item before performing the item.

My real code is triggering an AJAX call, and update the UI to update a scope variable so I am currently executing shortly after reaching the scope of my code, but Legacy code is failing because DOM elements are not yet available.

I can add an ugly delay with setTimeout (), but do not guarantee that Dome is actually ready.

My question is, is there any way I can bind to a "sung" incident?

  var myApp = angular.module ('myApp', []); MyApp.controller ("mycontroller", ['$ scope', function ($ scope) {var resultsToLoad = [{id: 1, name: "one"}, {id: 2, name: "two"}, {id : 3, name: "three"}] $ $ scope.results = []; $ scope.loadResults = function {for (var i = 0; i & lt; resultsToLoad.length; i ++) {$ Scope.results. Push (resultload [i]);}} by adding the function () {// do some awesome work to trigger the service call to log in}}]); Angular Bootstrap (document, ['myApp']);      

text ">

Use queue to perform that task Is scheduled to be out of the current stack frame, but before the render view of the browser -

OK, so what is "stack frame"? A githab comment more says:

If you encrypt with a controller, it will be first, but if you encrypt it with the instruction, it will be after that - / P>

Above, Misko is discussing it when the code is queued by $ evalAsync for execution, in relation to the DOM being updated by angular.

Then If the code is queued from the director using $ evalAsync, then it should run after the DOM. I suggest that before reading two Github comments, the angle has been tampered with, but the browser renders Before you. If something needs to be run after the render, or if a model updates after the controller, then use $ timeout (..., 0);

Also see, whatever is an example Bella who uses $ evalAsync ().

No comments:

Post a Comment