Binding select element to object in Angular

后端 未结 14 1671
走了就别回头了
走了就别回头了 2020-11-22 02:41

I\'d like to bind a select element to a list of objects -- which is easy enough:

@Component({
   selector: \'myApp\',
   template: `

My Application&

14条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 03:41

    My Application

    StackBlitz example

    NOTE: you can use [ngValue]="c" instead of [ngValue]="c.id" where c is the complete country object.

    [value]="..." only supports string values
    [ngValue]="..." supports any type

    update

    If the value is an object, the preselected instance needs to be identical with one of the values.

    See also the recently added custom comparison https://github.com/angular/angular/issues/13268 available since 4.0.0-beta.7

    
                            
        
    提交评论

提交回复
热议问题