I have found a solution. I added this to my component ngOnInit():this.type.updateValue(this.customer.type);
My component:
export class UpdateCustomerComponent implements OnInit {
myCustomerForm: ControlGroup;
lastname: Control;
type: Control;
constructor(routeParam: RouteParams, private dataService: ContactDataService, private builder: FormBuilder) {
this.lastname = new Control('',
Validators.compose([Validators.required])
);
this.type = new Control(this.customer != null ? this.customer.Type : null,
Validators.compose([Validators.required])
);
this.myCustomerForm = builder.group({
lastname: this.lastname,
type: this.type
});
}
ngOnInit() {
this.dataService.get(this.id).subscribe(data => {
this.customer = <ICustomer>JSON.parse(JSON.stringify(data));
this.lastname.updateValue(this.customer.Lastname);
this.type.updateValue(this.customer.Type);
});
}
}
source
share