I am encountering an issue with setting the default value of an Angular 2 Form (formbuilder). In my case, the default values are observables retrieved from a server, so I am unable to implement them in the usual way:
export class UserComponent implements OnInit{
userForm: ControlGroup;
userData: any; // Initialize the observable variable
ngOnInit():any {
this.userData = this._dataService.getAllData() // My Observable
.subscribe(
data => {
this.userData = data;
}
);
this.userForm = this._formBuilder.group({
// Setting the default value below
'username': [this.userData.username, Validators.compose([
this.usernameValid
])]
}
Does anyone have any suggestions on what changes need to be made? The form is currently not displaying anything inside the input fields...