Wednesday 27 March 2019

add style in angular2 using method

isBold: boolean = false;
  fontSize: number = 40;
  isItalic: boolean = true;

  addCustomStyles() {
      let styles = {
'font-weight': this.isBold ? 'bold' : 'normal',
          'font-style': this.isItalic ? 'italic' : 'normal',
          'font-size.px': this.fontSize
      };

      return styles;
  }

<button style='color:black' [ngStyle]="addCustomStyles()">Test Button</button>

No comments:

Post a Comment