Angular2:我们可以在模板中插入什么表达式 [英] Angular2: what expressions can we interpolate in template
问题描述
我读到我们可以插入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
关键字 - 使用分号或逗号链接表达式
- 递增(++)和递减运算符
- Assignment (= +=, -=)
- Using the
new
keyword - Chaining expressions using a semicolon or comma
- Increment (++) and decrement operators
此外,不支持像<$ c $这样的按位运算符c> | 或&
一般来说,放置复杂的东西是个好主意控制器或组件内的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屋!