angularjs-lifecycle

Error: $rootScope:inprog — What is the correct way to 'not' execute $apply in angular?

て烟熏妆下的殇ゞ 提交于 2019-12-24 10:57:41
问题 AngularJS Wiki - Anti-Patterns states the following: Don't do if (!$scope.$$phase) $scope.$apply() , it means your $scope.$apply() isn't high enough in the call stack. And I kind of understand this. There is a built in logic that determines when what needs to be executed. And when an external developer, without direct insigt in the runtime executions of different procedures, determines what should run where, it counteracts the framework. But I am currently uploading a large file where the

AngularJS - Accessing ng-init variables from run method

浪尽此生 提交于 2019-12-14 03:49:35
问题 1) I have variables initialized in ng-init Eg - ng-init="password='Mightybear'"; 2) I want to access it from the .run method. Eg - anguar.module("ngApp", []) .run(function() { //Access password here }); Below scenarios I have tried, and did not work - 1) angular.module("ngApp", []) .run(function($rootScope) { console.log($rootScope.password) //undefined!!! }); 2) angular.module("ngApp", []) .run(function($rootScope, $timeout) { $(timeout(function() { console.log($rootScope.password) /