Angularjs我可以更改从另一个控制器控制器的$范围值? [英] Angularjs Can I change $scope value of a controller from another controller?

查看:100
本文介绍了Angularjs我可以更改从另一个控制器控制器的$范围值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTML DIV,像

I have an HTML div , like

<div id="loader-container" data-ng-controller="LoaderController" ng-show="shouldShow">
Some html design
</div>

在我的控制器

angular.module('core').controller('LoaderController', ['$scope','$location', 'Authentication', '$rootScope',
function($scope,$location, Authentication, $rootScope) {
    $scope.shouldShow = true;
}

]);

而现在,我想隐藏从另一个控制器HTML DIV,这就是为什么我试图让$ scope.shouldShow变量从另一个控制器为假。那么,如何能够使

And now, I want to hide that html div from another controller, That's why I tried to make $scope.shouldShow variable as false from another controller. So how can I make

$scope.shouldShow = false;

从另一个控制器。是否有可能或另一种方式?

from another controller. Is it possible or any alternative way.?

推荐答案

每个控制器将创建一个新的范围。

every controller will create a new Scope.

因此​​,改变一个控制器的范围不会在其他控制器的范围反映。

Hence the changing the scope in one controller will not reflect in the scope of other controller.

如果您想要在整个控制器上创建 $ rootScope 变量,并用它来共享属性。

If you want to share a property across the controllers create that variable on the $rootScope and use it.

在控制器

$ $范围= root.shouldShow真实。 //或false

在标记

&LT; D​​IV NG秀=$ root.shouldShow&GT;&LT; / DIV&GT;

这篇关于Angularjs我可以更改从另一个控制器控制器的$范围值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆