I am trying to set the button name programmatically using *ngIfin Angular 2
My html layout is as follows
<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 method is setDefaultAttachmentas follows:
setDefaultAttachment (id:number){
this.defaultAttaschmentId = id ;
}
but I get this error:
EXCEPTION: Error: impurity (in promise): template analysis errors: Parser error: bindings cannot contain assignments in 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 value '" "): AttachmentsTabComponent @ 29: 126 * **
source
share