Give placeholder to select in Angular 6

后端 未结 7 2393
萌比男神i
萌比男神i 2021-02-19 15:25

I have a select option in which i want to give placeholder which says \"select a category\"

7条回答
  •  广开言路
    2021-02-19 16:01

    Since you're using ngModel, to be selected by default the value attribute of the option tag and the initial category value in the component class must be the same. And to make it hidden in the list you can use hidden attribute. For the consistency of validation issues the best way is to use ngValue instead of value.

    in the component:

    category: string = null;
    

    in the template:

    
    

提交回复
热议问题