Home > Mobile >  how to call different function based on condition with different button name? its angular related pr
how to call different function based on condition with different button name? its angular related pr

Time:10-16

<button type="button"   (click)="update()">Save</button>

<button type="button"   (click)="create()">Add</button>

I want to render buttons based on condition. in my form update should be called when I am editing and create should be called when I am creating also the name on button changes with save and add button based on this conditions.

Note: when calling the update function, the data is inside the form i.e. modaldata.id, but when calling create, no data is inside the form.

CodePudding user response:

You have to use ngIf for the conditional rendering

<button type="button" *ngIf="isUpdateCondition"   (click)="update()">Save</button>

<button type="button" *ngIf="isCreateCondition"   (click)="create()">Add</button>

when calling update function data is inside the form i.e; modaldata.id but when calling create no data is inside the form.

For the field which you want to pass has to be handled in the respective handler functions(update/create)

CodePudding user response:

Dear there are lot of ways to achieve that

  • one way of is by adding if conditions (can be set in multiways)
  • Other could be using routes by adding post fix to routes like /update or /create
  • Related