ng $scope() does not refresh the problem

I encountered a problem when developing the project in the past two days, that is, the code name in the controller was executed, but the page did not make any changes, probably using { {}} for two-way data binding, and $scope for the corresponding change operation , first you have to make sure there are no other errors, the scope $scope is fine, then you can consider $apply(). Important note: At this time, you are definitely not using ng's own things, for example, you are using jq or other third-party libraries

The $apply() function allows expressions to be executed inside the Angular context from outside the Angular framework. For example, you must use $apply() if you implement a setTimeout() or use a third-party library and want events to run inside the Angular context.

In short, the context is accessible from outside when using $scope.$apply(). If $apply() is called when an event is fired, it will be run using the Angular event loop. If $apply() is not called, this function will not be executed inside the event loop, but will run outside the Angular context

I copied the above two paragraphs, which are concise and clear. When using the ng-directive, $apply() will be called by default, and calling it will force a $digest (dirty check) loop

try this

$scope.$apply(function(){
          $scope.est = "Just A Test!"
        })
It is best to use the above way of nesting functions inside


Additional links to related articles

English original

Chinese translation

7 suggestions for ng performance tuning, ng-reapt two-way binding more than 2500 will be slow

http://www.csdn.net/article/2013-09-18/2816972-AngularJS-performance-tuning-for-long-list

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324350714&siteId=291194637