jus*_*opi 22 binding transclusion angularjs-directive angularjs-scope
我刚刚了解到你可以通过以下方式选择"反向"或回调绑定:
scope: { parentScopeFunc: '&?' }
Run Code Online (Sandbox Code Playgroud)
我试图看看是否有办法用双向绑定做类似的事情.
scope: { optional2WayBoundProp: '=?' }
Run Code Online (Sandbox Code Playgroud)
我尝试使用链接函数的element&attrsparams,但后来我失去了回到父级的双向绑定.该方法仅允许父对子更新.然后我不妨使用@范围机制.
我发现这个问题Angular JS指令,在链接函数中更改了2路数据绑定,以便回答有关的主要问题=?.但是它没有解决'可选'非约束值,如true或false.
这就是我想要完成的事情:
编写一个面板指令,用于转换内容,并且可以在标题区域之外进行折叠:
<my-panel>
<transcluded-header-content/>
<button ng-click="toggleCollapse()"/>
<transcluded-body-content ng-if="isExpanded"/>
</my-panel>
在某些情况下,我想在父作用域中缓存面板实例的折叠状态(因此,双向绑定视图的控制器可以确定如何缓存此信息):
<my-panel is-expanded="parentScopeProp">
<my-panel is-expanded="true/false">据我所知,通过=分配,那表情像undefined,true及false无法评估.