Angular2:我们可以在模板中插入哪些表达式 [英] Angular2: what expressions can we interpolate in template

查看:27
本文介绍了Angular2:我们可以在模板中插入哪些表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读到我们可以插入 Javascript 表达式.我们可以插入的有效 Javascript 表达式列表是什么?到目前为止,对于插值,我有一个显示的属性,例如.object.property,像 {{1+1}} 这样的短表达式,我们还可以插入哪些 Javascript 表达式?

I read that we can interpolate Javascript expressions. What is the list of valid Javascript expressions that we can interpolate? So far for interpolation I have a displayed property, eg. object.property, short expressions like {{1+1}} what else Javascript expressions can we interpolate?

推荐答案

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

这篇关于Angular2:我们可以在模板中插入哪些表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆