how to condition a text box in template driven form in angular 10

Viewed 52

I am new to angular , i am writing in template driven form html. I need to code such a way that when from backend service we get one value for user email it should be pre populated in text box and if multiple emails are there then populate a editable drop down. Can someone help me here.

1 Answers

inside your component you could have a method that checks whether there are actually multiple emails available, something like

// totally depending on your actual implementation
function hasMultipleEmails(): boolean {
    return Array.isArray(yourUser.email.variable);
}

and then you can check in your template with this function and actual implement two different layouts. For example

<input type="text" *ngIf="!hasMultipleEmails()"/>
<div *ngIf="hasMultipleEmails()">
    Your dropdown here
</div>
Related