src/pages/home/home.html
1 2 3 4 5 6 7 8 9 10 11 |
<ion-header> <ion-navbar> <ion-title> Ionic Blank </ion-title> </ion-navbar> </ion-header> <ion-content padding> <div [ngStyle]="{'background-color': timeColor}">Hello World</div> </ion-content> |
src/pages/home/home.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import { Component } from '@angular/core'; import { NavController } from 'ionic-angular'; @Component({ selector: 'page-home', templateUrl: 'home.html' }) export class HomePage { timeColor: string; constructor(public navCtrl: NavController) { if (1==1) { this.timeColor = '#F00'; // Red } else { this.timeColor = '#0F0'; // Green } } } |
บรรทัดที่ 13: 1==1
จะได้สีแดง
บรรทัดที่ 13: 1==2
จะได้สีเขียว
Link