Differences between value and ngValue in Angular 5

前端 未结 5 432
轮回少年
轮回少年 2020-11-29 06:54

Today I realized about an unexpected (for me) behaviour of the reactive forms in Angular 5. The server was receiving from the app an string with the value "null" i

5条回答
  •  一生所求
    2020-11-29 07:40

    ngValue is valuable when you need to bind to object in the object collection instead of string that is displayed by option element as an example as follows.

      
    

    where

      colors: [{code:'#FF0000', name:'Red'}, {code:'#00FF00', name:'Green'}, {code:'#0000FF', name:'Blue'}];
    

    selectedColor is one of the color object above.

提交回复
热议问题