本文介绍了bindToController:对象的指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

指令 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 的填补1.5和2.0之间的差距,而范围绑定一直没有使用。

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.

推荐答案

对面,那是相当的解释。

Just stumbled across this PR, it is quite explanatory.

我不知道是否有在具有两个不同的绑定实际利益范围:{...} 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:对象的指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-12 16:46