Set initially selected item in Select list in Angular2

后端 未结 7 1175
独厮守ぢ
独厮守ぢ 2020-12-07 23:59

I\'ve managed to get a Select list to bind with my model for the purpose of saving, but I cannot work out how to make Angular2 automatically select the correct option on the

7条回答
  •  感动是毒
    2020-12-08 00:40

    If you use

    
    

    You need to set the property object in you components class to the item from objects that you want to have pre-selected.

    class MyComponent {
      object;
      objects = [{name: 'a'}, {name: 'b'}, {name: 'c'}];
      constructor() {
        this.object = this.objects[1];
      }
    }
    

提交回复
热议问题