blackHawk
blackHawk

Reputation: 6307

Angular2: what expressions can we interpolate in template

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?

Upvotes: 4

Views: 3317

Answers (2)

Nageswara Rao Maridu
Nageswara Rao Maridu

Reputation: 157

You can use the Angular 2 default pipes for evaluating the expression inside an interpolation. Please refer the below link https://www.npmjs.com/package/angular2-pipes#sum

Upvotes: 0

Richard Hamilton
Richard Hamilton

Reputation: 26444

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

Upvotes: 3

Related Questions