当父级范围变量发生变化时,如何更新指令?

时间:2017-02-06 21:59:02

标签: javascript angularjs angularjs-directive angularjs-scope

Directive:
<div ng-show="{{ show }}">
        ...
</div>

angular.module('mymodule').directive('mydirective', [
  function () {
    return {
        scope: {
            show: '='
        },
        ...
    };
}]);

Parent:
<div mydirective show="show" ng-repeat="item in items">
</div>

controller.js:
this.show = false //intially

function changeVisibility(){
  this.show = true; //how to tell the directive about this change?
} 

&#34;显示&#34;是一个最初为false的范围变量,但后来变为true。但是,该指令的范围变量&#34;显示&#34;发生这种情况时不会更新。当父母的变量变化时,如何更新指令的show变量?我需要一个$ scope。$ watch还是什么?

1 个答案:

答案 0 :(得分:0)

ng-show期望表达式不是插值

尝试

ng-show="show"