How to set first option as selected where options build from loop in select box anular 4

后端 未结 3 1323
孤城傲影
孤城傲影 2021-01-28 06:41

I have worked on angular 4 project, In this project, I have a requirement to set the first option as selected where all options are created dynamically by loop. html code:

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-28 07:13

    Try like this :

    
    

    component.ts

    export class HomeComponent implements OnInit {
    
        private selectedServiceType: any;
        private services: Array = [];
    
        constructor() {
            this.services = [{
                name: "Harish",
                value: 5000
            }, {
                name: "Chandru",
                value: 5001
            }]
        }
        onChange(e) {
            this.selectedServiceType = e.target.value;
        }
    }
    

提交回复
热议问题