javascript - 为什么 Angular 2 或 Angular 4 使用香蕉括号?有什么具体原因吗?为什么他们不遵循与 Angular 1 相同的模式?

标签 javascript angularjs angular typescript web

我知道它与任何编码无关,但它们可以遵循与 Angular 1 中相同的语法

<input ng-model="hero.name" placeholder="name" type="text">

到目前为止,AngulAR 2 及其更高版本的语法

 <input [(ngModel)]="hero.name" placeholder="name" type="text">

如果他们这样做,对人们适应 Angular JS 的变化会有很大帮助吗?

ng-repeat类似,他们改为ngFor

<ul ngFor let-item [ngForOf]="items" let-i="index" [ngForTrackBy]="trackByFn">
  <li>...</li>
</ul>
<ul ng-repeat="item in items track by myTrackingFunction(n)">
<li>...</li>
</ul>

最佳答案

香蕉括号用于双向绑定(bind)。

Binding syntax:

Data binding is a mechanism for coordinating what users see, with application data values. While you could push values to and pull values from HTML, the application is easier to write, read, and maintain if you turn these chores over to a binding framework. You simply declare bindings between binding sources and target HTML elements and let the framework do the work.

Angular provides many kinds of data binding. This guide covers most of them, after a high-level view of Angular data binding and its syntax.

Binding types can be grouped into three categories distinguished by the direction of data flow: from the source-to-view, from view-to-source, and in the two-way sequence: view-to-source-to-view.

关于javascript - 为什么 Angular 2 或 Angular 4 使用香蕉括号?有什么具体原因吗?为什么他们不遵循与 Angular 1 相同的模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43607916/

相关文章:

javascript - h5Validate 函数调用应在表单验证时完成

javascript - 使用 jQuery 检查 4 个数字和 2 个字母的输入

javascript - 如何将保存 Html 的 Javascript 变量转换为字符串?

javascript - 带有 Razor 表达式的 ng-init

XMLHTTPRequest 的 Angular 2 打字问题

javascript - 在 Angular2 中循环时,数据未呈现在屏幕上

javascript - 如何强制 Android 互联网浏览器立即显示样式更改

javascript - AngularJS 动态表单字段验证

javascript - 在 Angular 8 中创建过滤管道

javascript - 反转带有特殊字符的字符串