Angular value vs ngvalue

preview_player
Показать описание
In this video we will discuss how to validate a select element if it has a custom option like "Please Select" etc. Along the way we also discuss the difference between value and ngValue in Angular.

Healthy diet is very important for both body and mind. We want to inspire you to cook and eat healthy. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking.

If you use value, null is treated as a string and not as a null. Hence the required validation does not work.

If you just want the selected value as a string then use value property.

If you want the selected object from the SELECT element, then use ngValue.

Use the disabled attribute, if you do not want the user to be able to select the first default option.

The built-in required validator will only work with the SELECT element, if the default option value is null.

Text version of the video

Slides

Angular CRUD Tutorial

Angular CRUD Tutorial Text Articles & Slides

All Dot Net and SQL Server Tutorials in English

All Dot Net and SQL Server Tutorials in Arabic
Рекомендации по теме
Комментарии
Автор

One of the best teachers on Youtube. Thank you so much!

olio
Автор

A quick tip! you can use style *display:none* on the placeholder option. In such way it will show the option at start and it wont get be shown at dropdown. i.e.) <option selected style="display:none">Select Department</option>

pranesh
Автор

Somehow randomly came across this when trying to work out this exact issue with [value]="null", great explanation thanks!

MrVassa
Автор

you are always great sir .. one more solution is here that we can use blank value instead of null.

VipinRawat_Offcial
Автор

Great work. The disabled tip was very useful too.

FernsDad
Автор

Please make videos on integrating angular cli with asp. Net

rafayjangsher
Автор

sir can you please do that validation with pre-defined html validation??

rockydinesh
Автор

which version of angular you are using ??

hannykhan
Автор

Hai sir, please share some custom form validation videos.

saikumarduggana
Автор

when we write <option [ngValue]=null>Select department</option> then it works but not works "null"

chandankumarsingh
Автор

This technique doesn't work now. Try this instead:

<option disabled value="undefined">Select Department</option>

debarghyachakraborty