问题描述
指令 bindToController
可以是布尔值或对象,后者显示为 此处:
Directive bindToController
can be either boolean or object, the latter is shown here:
myMod.directive('myDirective', {
controller: 'MyDirectiveController',
bindToController: {
name: '@'
}
});
但没有记录在案的事实引发了问题.为什么要首先制作 bindToController: { ... }
功能?有没有有用的场景?
But the fact that it was not documented raises questions. Why bindToController: { ... }
feature was made in the first place? Are there useful scenarios for it?
尽管 bindToController 主要不是为了,看看它现在如何在 angular.component
中使用很有趣 作为 bindings
属性 来填补 1.5 和 2.0 之间的空白,而 scope 绑定保持未使用.
Despite bindToController wasn't primarily intended for that, it is interesting to see how it is utilized now in angular.component
as bindings
property to fill the gap between 1.5 and 2.0, while scope
bindings remain unused.
推荐答案
刚刚偶然发现 这个PR,解释的很清楚.
Just stumbled across this PR, it is quite explanatory.
我不确定在 scope: { ... }
和 bindToController: { ... }
中使用两个不同的绑定是否有实际好处.但它最终也将绑定带到了原型继承范围:
I'm not sure if there is practical benefit in having two different bindings in scope: { ... }
and bindToController: { ... }
. But it finally brings the bindings to prototypically inherited scope as well:
bindToController: {
text: '@text',
obj: '=obj',
expr: '&expr'
},
scope: true
这篇关于bindToController:指令中的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!