Skip to main content

Posts

Showing posts with the label Difference between ngValue and value in angular

Angular ngValue vs value | Angular 9, 8, 7, 6, 5, 4, 2

Difference between ngValue and value in angular - We are open to use Angular value or ngValue and the only difference between two is that the “value” is always “string”, where in “ngValue” you can pass “object”. Let’s see the below examples in details, Example 1, const items = [ "Anil" , "Sunil" , "Sushil" ] Use of value - < option * ngFor = "let item of items" [ value ]= "item" >     {{ item }} </ option > Result - using [value] when one of the options is selected the value will be Anil, Sunil, Sushil. Use of ngValue - < option * ngFor = "let item of items" [ ngValue ]= "item" >     {{ item }} </ option > Result - using [ngValue] when one of the options is selected the value will be 0: Anil, 1: Sunil, 2: Sushil Example 2 , import { Component } from '@angular/core' ; @ Component ({   selector: 'example-app' , ...