Angular 组件:单向绑定和属性绑定有什么区别?

Angular Components: What is the difference between one-way and attribute bindings?

我一直在构建一些 angular 组件,想知道单向 ("<") 和属性 ("@") 绑定之间的实际区别是什么?

是否存在其中一种优于另一种的情况?很简单,属性总是不可变的字符串,必须插值?

来自https://docs.angularjs.org/guide/component

@ bindings can be used when the input is a string, especially when the value of the binding doesn't change.

来自 https://docs.angularjs.org/api/ng/service/$compile#-scope-

"@" - bind a local scope property to the value of DOM attribute. The result is always a string since DOM attributes are strings.

"<" - set up a one-way (one-directional) binding between a local scope property and an expression passed via the attribute

因此,使用“@”来传递字符串值。该值可以是一个简单的字符串值,例如myattr="hello",或者它可以是一个 AngularJS 嵌入了表达式的内插字符串,例如myattr="my_{{helloText}}".