$scope. safeapply = function (fn) {var phase = this. $root. $ $phase; if (phase = = ' $apply ' | | phase = = ' $digest ') {if (FN && (typeof (fn) = = = ' function ')) {fn (); }} else {this. $apply (FN); }};
When using Ng, you will encounter the situation of dynamically adding data, it is possible after you add data dynamically after the page because the rendering has been completed so that the newly added data can not be displayed on the page
If using the Select tag:
<select id= "Uidselect" class= "sel" ng-model= "Sid" Ng-init= "" ng-options= "user.name for user in users" > <option V Alue= "" Default>-select one-</option></select>
Since the data of the users array at the beginning is fixed, then if we want to add data to users after that, then the drop-down option will not change, and the various strategies of Niang will tell you to add $scope. $apply () on it. ... However, it is possible to add the following error message [$rootScope: InProg] $apply already in progress, so it is only necessary to use the method provided above,
First the top safeapply method into your scope, and then dynamically add the data after the use of $scope. safeapply (); You can have it ....
AngularJS's safety apply