2017-06-21 83 views
0

ng-class指令不能編譯,在檢查器中運行時可見。Ang-ng類不能編譯/工作

TS腳本

export class TotalPage { 

    showClass: boolean; 

    constructor(public navCtrl: NavController ,public http: Http) { 

     this.showClass = false; 

    } 

} 

HTML

<ion-header> 

    <ion-navbar> 
    <ion-title>Total</ion-title> 
    </ion-navbar> 

</ion-header> 

<ion-content padding> 
    <div ng-class="{expenceBg:showclass}">Test</div> 
</ion-content> 

SCSS

$expence-bg: #ffcccc; 
$income-bg: #00cccc; 
page-total { 
    .expenceBg{ 
     background-color: $expence-bg; 
    } 
    .incomeBg{ 
     background-color: $income-bg; 
    } 
} 

.expenceBg{ 
     background-color: $expence-bg; 
    } 

所以,當我運行它,它有測試因此它不會是 「NG」 級部分編譯。我究竟做錯了什麼?

+2

嘗試[ngClass] =「{expenceBg:showclass}」' – SaiUnique

回答

2

ng-class僅用於AngularJS,不用於Angular(2+)。改爲使用[ngClass]

<ion-content padding> 
    <div [ngClass]="{expenceBg:showclass}">Test</div> 
</ion-content>