角指令与NG-ATTR势必模型 [英] Angular directive with ng-attr bound to model
本文介绍了角指令与NG-ATTR势必模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要仔细绑定指令范围和改变从外面属性的属性
它改变了指令内在的东西。
I want to double-bind an attribute to directive scope and changing that attribute from outside it changes something inside the directive.
<body ng-app="paneApp" ng-controller="AppCtrl">
<div class="btn-group">
<button type="button" class="btn btn-primary" ng-model="pane.a" btn-checkbox>A</button>
<button type="button" class="btn btn-primary" ng-model="pane.b" btn-checkbox>B</button>
<button type="button" class="btn btn-primary" ng-model="pane.c" btn-checkbox>C</button>
<button type="button" class="btn btn-primary" ng-model="pane.d" btn-checkbox>D</button>
</div>
Visible: {{pane.a}} {{pane.b}} {{pane.c}} {{pane.d}}
<pane-container>
<pane ng-attr-hidden="{{pane.a}}">A</pane>
<pane>B</pane>
<pane>C</pane>
<pane>D</pane>
</pane-container>
</body>
这里的错误是:
Error: [$parse:syntax] Syntax Error: Token 'pane.a' is unexpected, expecting [:] at column 3 of the expression [{{pane.a}}] starting at [pane.a}}].
如果不使用attirbute内的前pression,预期所有的作品:
If not using an expression inside the attirbute, all works as expected:
<pane ng-attr-hidden="{{pane.a}}">A</pane>
编辑:
此示例按预期工作: preVIEW在plunker
推荐答案
我假设NG-ATTR隐藏预计角前pression,但你给它一个对象定义。结果
请尝试删除 {{}}
I'm assuming ng-attr-hidden expects an angular expression, but you're giving it an object definition.
Try removing the {{}}
<pane ng-attr-hidden="pane.a">A</pane>
这篇关于角指令与NG-ATTR势必模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文