2016-07-28 10 views
3

私は*ngIfを使用してプログラムボタン名を設定しようとしています角度2* ng?角度2のボタンテキストを設定する代わりに?

私のHTMLは、私のsetDefaultAttachment方法は、次のようになります。この

<button type="button" class="btn btn-primary" style="margin-top:5px;" (click)="setDefaultAttachment(img.id)" *ngIf ="defaultAttaschmentId === img.id ? buttonName ='Default Image' : buttonName ='Set As Default'" > {{buttonName}}</button> 

のようなルックスをモックアップ:

setDefaultAttachment (id:number){ 
    this.defaultAttaschmentId = id ; 
} 

が、このエラーが表示されます:

EXCEPTION: Error: Uncaught (in promise): Template parse errors: Parser Error: Bindings cannot contain assignments at column 52 in [ngIf defaultAttaschmentId === img.id ? buttonName ='Default Image' : buttonName ='Set As Default'] in [email protected]:126 ("pe="button" class="btn btn-primary" style="margin-top:5px;" (click)="setDefaultAttachment(img.id)" [ERROR ->]*ngIf ="defaultAttaschmentId === img.id ? buttonName ='Default Image' : buttonName ='Set As Default'""): [email protected]:126***

答えて

6

このように直接使用してください。

<button type="button" class="btn btn-primary" style="margin-top:5px;" (click)="setDefaultAttachment(img.id)"> {{defaultAttaschmentId === img.id ? 'Default Image' : 'Set As Default'}}</button> 
関連する問題