前端老生

Angular中ngValue和value的区别

最近在用angula中的option时传递一个对象遇到问题,使用[value]绑定对象输出'[Object object]' 获取值失败。

解决办法

[value]改为[ngValue]

原因:

value 用来绑定字符串,ngValue用于对象绑定

 

PropertyDescription
id: stringID of the option element
@Input()
ngValue: any

Write-only.

Tracks the value bound to the option element. Unlike the value binding, ngValue supports binding to objects.

@Input()
value: any

Write-only.

Tracks simple string values bound to the option element. For objects, use the ngValue input binding.