Add user id as from attribute

Asjad Butt 71 Reputation points
2022-11-25T07:55:28.49+00:00

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

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,157 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 55,601 Reputation points
    2022-11-28T23:39:42.987+00:00

    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.

    0 comments No comments