Angular2: what expressions can we interpolate in template

前端 未结 2 1185
囚心锁ツ
囚心锁ツ 2021-01-19 06:24

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

2条回答
  •  滥情空心
    2021-01-19 06:59

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

    JavaScript expressions that promote side effects are prohibited including

    • Assignment (= +=, -=)
    • Using the new keyword
    • Chaining expressions using a semicolon or comma
    • Increment (++) and decrement operators

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

    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

提交回复
热议问题