注意指令之外的表达式更改

时间:2016-04-01 14:12:01

标签: angularjs angularjs-directive

我有一个指令:

<my-directive data-watched-expression='watchedAttribute1 || watchedAttribute2'> </my-directive>

在指令模板中我有:

<input ng-readonly="{{watchedExpression}}"/>

当属性watchedAttribute1或watchedAttribute2在指令之外发生变化时,能够重新评估表达式的最佳解决方案是什么? 如果可能的话,我想在没有将这些变量传递给指令的情况下实现这一目标......

1 个答案:

答案 0 :(得分:1)

ng-readonly指令采用Angular表达式。不要使用插值。

<!-- Do this -->
<input ng-readonly="watchedExpression"/>

<!-- Not this
<input ng-readonly="{{watchedExpression}}"/>
-->

内插ng-srcng-srcsetng-href指令。其他属性指令采用Angular表达式。

相关问题