Angular 2 - Setting selected value on dropdown list

前端 未结 8 1180
天命终不由人
天命终不由人 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:00

    Actually if You use ReactiveForms i found this way much easier to acomplish:

    If the form is defined like this:

    public formName = new FormGroup({
    
        fieldName: new FormControl("test") //where "test is field default value"
    
    });
    

    Then thats the way You can change its value:

    this.formName.controls.fieldName.setValue("test 2"); //setting field value to "test 2"
    

提交回复
热议问题