[英]Can I call $rootScope.$emit inside a $rootScope.$on function?
[英]From run block can i able to call angular scope function inside another controller instead of $rootscope
我需要从runblock的某些控制器中调用angular Scope函数。 我可以调用该函数,还是需要使用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'];
myAPP.run(function ($rootScope, $state,$scope) {
这里不能将$scope
对象作为第三个参数,因为$scope
和$controller
对象都是在compiling and linking phase
创建的,该阶段在run
阶段执行之后,在run
阶段执行run
块。 因此,您不能在运行块中包含它们。 由于$rootScope
是一项服务,因此只有$rootScope
在run
块中可用,并且只有服务在run
块中可用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.