AngularJS {foo : "="} 和 {foo : "=myFoo"} 之间的范围绑定区别

AngularJS scope binding difference between {foo : "="} and {foo : "=myFoo"}

我一直在 angular 开发一些 Web 应用程序,并且看到了两种不同的方法来绑定作用域上的变量。每当我认为我已经弄清楚有什么不同时,我总是错了。我找遍了,找不到明确的答案。

有什么区别

scope:
{
   foo : "="
}

scope:{
   foo : "=foo"
}

我一直在用top版本,好像还不错,但是我想知道bottom版本是什么(以及两边的变量是干什么用的),以免漏掉angular 必须提供的任何强大功能。

第二个允许您将范围映射到标记中的不同名称。

在此处查看隔离指令范围部分中的示例:

https://docs.angularjs.org/guide/directive

这篇笔记提供了一些有用的信息:

The scope option is an object that contains a property for each isolate scope binding. In this case it has just one property:

  • Its name (customerInfo) corresponds to the directive's isolate scope property customerInfo.
  • Its value (=info) tells $compile to bind to the info attribute.

这也很有用。

These =attr attributes in the scope option of directives are normalized just like directive names. To bind to the attribute in bind-to-this="thing", you'd specify a binding of =bindToThis.