且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Angular2:我们可以在模板中插入哪些表达式

更新时间:2023-12-01 18:25:52

Angular2 中的表达式在允许的范围方面与 Angular 中的表达式非常相似.

Expressions in Angular2 are very similar to expressions in Angular in terms of the scope of what they allow.

禁止促进副作用的 JavaScript 表达式,包括

JavaScript expressions that promote side effects are prohibited including

  • 赋值 (= +=, -=)
  • 使用 new 关键字
  • 使用分号或逗号链接表达式
  • 递增 (++) 和递减运算符

此外,不支持像 |&

Furthermore, there is no support for bitwise operators like | or &

通常,***将复杂的 JavaScript 逻辑放在控制器或组件中,而不是放在视图中.这是因为关注点分离的设计原则,使代码更加模块化和可读.

Generally, it's a good idea to put complex JavaScript logic inside a controller or component, instead of inside a view. This is because of the Separation of Concerns design principle and making code more modular and readable.

https://angular.io/docs/ts/latest/guide/template-syntax.html#!#template-expressions