I am trying to set button name programmatically using *ngIf
in Angular 2
My html mock up looks like this
<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>
My setDefaultAttachment
method looks like this :
setDefaultAttachment (id:number){
this.defaultAttaschmentId = id ;
}
but I am getting this error :
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 AttachmentsTabComponent@29: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'""): AttachmentsTabComponent@29:126***
use it directly like this
<button type="button" class="btn btn-primary" style="margin-top:5px;" (click)="setDefaultAttachment(img.id)"> {{defaultAttaschmentId === img.id ? 'Default Image' : 'Set As Default'}}</button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With