Angular 4 - using objects for option values in a select list

后端 未结 6 1035
南旧
南旧 2020-12-23 20:25

I know that similar questions have been asked, but I\'ve found none with a good answer. I want to create a select list in an Angular form, where the value for each option is

6条回答
  •  既然无缘
    2020-12-23 20:51

    HTML:

    
    

    TS:

    years = new FormControl('');
    yearsList = [{id: 1, value: '2019'}, {id:2, value: '2020'}];
    
    this.years.valueChanges.subscribe((year) => {
     console.log(year)
    });
    

    RESULT: you will get year object in console :)

提交回复
热议问题