我需要調用從runblock一些控制器內部的角度範圍功能。我可以調用函數,否則需要使用rootScope或$ scope.apply。
第一種方法:
myAPP.run(function ($rootScope, $state,$scope) {
$scope.menupage();
});
var SampleController = function ($scope,$localStorage) {
$scope.menupage =function()
{
// some logic
};
});
SampleController.$inject = ['$scope','$localStorage'];
否則需要使用這樣的
myAPP.run(function ($rootScope, $state,$scope) {
$scope.$apply(function() {
$scope.menupage();
});
});
var SampleController = function ($scope,$localStorage) {
$scope.menupage =function()
{
// some logic
};
});
SampleController.$inject = ['$scope','$localStorage'];
的'run'塊只有$ rootScope。它沒有自己的範圍。 。 – georgeawg
$ rootScope $應用可用,以及所有的$ rootScope.Scope方法:$手錶,$ EVAL,$上$廣播等欲瞭解更多信息,請參見[AngularJS $ rootScope.Scope API參考(HTTPS: //docs.angularjs.org/api/ng/type/$rootScope.Scope) – georgeawg