Jagadeesh Govindaraj Jagadeesh Govindaraj - 1 year ago 210
TypeScript Question

Math functions in angular2 bindings

Is there a way to use math functions in angular2 bindings?


<div class="partition-panel">
<b class="pull-left">{{Math.round(variable/12*2)}}</b>
<b class="pull-right">{{Math.round(variable/12*2)}}</b>

when try to use this i got error

Cannot read property 'round' of undefined

Also the similar question is answered for angular1

Answer Source

You can try this :

  selector: 'my-app',
  template: `
      <h2>Hello {{this.Math.round(this.number)}}</h2>
export class App {
  number: number;
  Math: any;
  constructor() {
    this.Math = window.Math;
    this.number = 2.5