AngularJS组件中

时间:2018-03-15 08:25:49

标签: angularjs angularjs-components two-way-binding

我正在创建一个AngularJS组件

var notificationComponent = {
        templateUrl: "notification.html",
        controller: ['$rootScope', notificationController],
        bindings: {
            visible: "="
        }
    };

我想在HTML中使用,如下所示:

<notification visible="$rootScope.showNotification"></notification>

基本上我想控制可见&#39;来自任何其他组件的属性为真或假。

我尝试通过在名为 showNotification $rootScope中维护变量来实现此目的。但是,如果我从任何其他组件修改其值,如:

$rootScope.showNotification = true;

它没有改变&#39; 可见&#39;适当的价值。

根据我的理解,下面的代码在AngularJS组件中进行双向绑定。

bindings: {
            visible: "="
        }

有人可以告诉我哪里出错了吗?

1 个答案:

答案 0 :(得分:3)

应该{​​{1}}访问$root

$rootScope

<强>&GT; demo fiddle

相关问题