Angular 2 - Setting selected value on dropdown list

前端 未结 8 1181
天命终不由人
天命终不由人 2020-12-04 16:29

I have run into an issue in pre-selecting values on a dropdown list in Angular 2.

I set an array of colours in the component which I bind successfully to the drop

8条回答
  •  南笙
    南笙 (楼主)
    2020-12-04 17:03

    This Example solution is for reactive form

     
    

    In the Component:

    this.formGroup.patchValue({
            preferredBankAccountId:  object_id_to_be_pre_selected
          });
    

    You can also give this value where you initialize your formGroup or later,depending on your requirement.

    You can do this by using [(ngModel)] binding also where you don't have to initialize your formControl.

    Example with [(ngModel)] binding

     
    

    Here, matchedCity is one of object within cities.

提交回复
热议问题