可选的双向对角分离指令约束范围 [英] Optional two-way binding on isolate scope for Angular Directive
问题描述
我刚刚得知你可以有一个可选的反向或回调结合通过:
I just learned that you can have an optional 'reverse' or callback binding via:
scope: { parentScopeFunc: '&?' }
我想看看是否有一种方法做的2路绑定类似的东西。
I'm trying to see if there is a way to do something similar with the 2-way binding.
scope: { optional2WayBoundProp: '=?' }
我试图与连接功能的元素
&安培; ATTRS
PARAMS但后来我失去了2路结合回父。该方法只允许父母对子女的更新。然后,我可能也仅仅使用 @
范围的机制。
I tried with the link function's element
& attrs
params but then I lose the 2-way-binding back to the parent. That method only allows for parent-to-child updates. Then I might as well just be using @
scope mechanism.
我发现这个问题,<一个href=\"http://stackoverflow.com/questions/22665363/angular-js-directive-change-a-2-way-data-binding-in-the-link-function\">Angular JS指令,改变一个2路数据链接功能绑定,这样回答关于主要问题 = <?/ code>。然而,它并没有解决可选非绑定的值,如
真正
或假
。
I found this question Angular JS directive, change a 2 way data binding in the link function so that answers the main question regarding =?
. However it doesn't solve the 'optional' non-bound value such as true
or false
.
下面就是我要完成的:
-
编写transcludes内容,并可折叠除了标题区面板指令:
&LT;我-面板&gt;
&LT; transcluded头内容/&GT;
&LT;按钮NG点击=toggleCollapse()/&GT;
&LT; transcluded体内容NG-IF =isExpanded/&GT;
&LT; /我-面板&gt;
在某些情况下,我想缓存在父范围面板实例的折叠状态(因此2路结合,其视图的控制器可以决定如何缓存此信息):
&LT;我的面板被展开=parentScopeProp&GT;
in some cases I want to cache the collapsed state of the panel instance in a parent scope (hence the 2-way binding where the view's controller can determine how to cache this info):
<my-panel is-expanded="parentScopeProp">
据我了解,通过使用 =
分配,即前pressions像未定义
,真正
&安培; 假
无法评估。
I understand that by using the =
assignment, that expressions like undefined
, true
& false
cannot be evaluated.
推荐答案
=?
是一个有效的范围分配为NG 1.2.x版本的...
'=?'
is a valid scope assignment as of ng 1.2.x...
...至于有从可选的双向结合插值的前pression手段的能力,这是仍待价而沽。
...as for the ability to have a means of interpolating an expression from an optional two-way-binding, that is still up for grabs.
这篇关于可选的双向对角分离指令约束范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!