you will need to make an ajax call to get the server data. as ngOnInit does not support async calls, you will need to defer the setup until after. if you could render the data on the initial page render as a javascript variable then just access variable.
Add user id as from attribute
Asjad Butt
71
Reputation points
Hi so im creating a form in angular with asp.net core as the back end and i use angular forms now i want is that when i initialize the form group i want one of the field's data to come from the server note that the data that should come from the server is a foreign key in the table that is going to recieve data fromthe form
ngOnInit(): void {
this.getTeacher();
this.getClass();
console.log(this.user);
this.classForm = new FormGroup({
classname: new FormControl('',[Validators.required]),
classtime: new FormControl('', [Validators.required]),
teacherId: new FormControl({value:, disabled: false},[Validators.required])
})
}
In the value attribute i want the value to come from the back end i tried decalring a varible on top that uses the interface of the user(teacherid) and adding it there like
inputuser:Users;
teacherId: new FormControl({value:this.inputuser.id, disabled: false},[Validators.required])
which still gives an error any idea how to