1

I am wondering if there is a way to check for more then true or false for an interpolated. In my case i have a form which i want to update the bttn based one the state of the form.

<button  (click)="saveEmail()"  [disabled]="emailEditForm.invalid" mat-raised-button color="primary">{{ mode }} </button>

the above is my current code and mode can be either , Save, Update, Duplicate but i would like the text to be more User friendly like. Create New Email, Update Email, Duplicate current Email. Is this posible or is this another case of having to use *ngIf ?

1 Answer 1

1

There are multiple ways actually..

1. Inline if:
 <button  (click)="saveEmail()"  [disabled]="emailEditForm.invalid" mat-raised-button color="primary">{{ mode=="Save"? "Create New Email":mode=="Update"? "Update Email": "Duplicate current Email" }} </button>

2 Cleaner way:

//TS

export class MyComponent {
    public Modes = { Save: "New Email", Update: "Update Email", Duplicate : "Duplicate current Email"  };
}

//HTML

<button  (click)="saveEmail()"  [disabled]="emailEditForm.invalid" mat-raised-button color="primary">{{ Modes[mode] }} </button>

Hope this helps

Sign up to request clarification or add additional context in comments.

1 Comment

The cleaner way is the way to go as it avoids endless chaining of values

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.