Skip to content Skip to sidebar Skip to footer

Validation For Select Field Angular 2

I am using angular2@2.4.1 release. How would i do a validation on select field?

Solution 2:

Try changing the value in your default option to an empty string:

<option [value]="">Select a school</option> 

Solution 3:

I run into the same kind of situation and the below snippet seems to work pretty good.

<option [ngValue]="undefined">Select a school</option>

Solution 4:

When adding ngForm to your name for your form your validation should work. I assume that is missing, because otherwise your form validation would work as is. So the only thing you would need is to add to your formtag is the aforementioned ngForm, like so:

<form #form="ngForm">

Here's a plunker

Solution 5:

I believe you should be able to implement a [disabled]="checkSelectFunction()" on your button and then create a function to check if no value is chosen in the select field.

Post a Comment for "Validation For Select Field Angular 2"