I have a form that uses ngModel to show data. It works great if I just load the information synchronously however when I try to use asynchronous code code nothing ever shows up. I know the field names are correct since, as I said, it works with synchronous code. I am sure it is something stupid I missed but I cannot figure out what. Here are some code snippits:
userinformation.service.ts
getuserinformation(): Promise<UserInformation> {
return Promise.resolve(MOCKUSERINFORMATION[0]);
}
userinformation.component.ts
getUserInformation(): void {
this.userinformationservice.getuserinformation().then(userdata => this.userinfo = userdata);
}
userinformation.component.html
<input type="text" autofocus="autofocus" name="FirstName" id="firstname" required="required" placeholder="First Name" class="required" ([ngModel])="userinfo.FirstName" />
Turns out I was using the wrong type of C# MVC Controller. I was using one based off of the "Controller" object which should be used for redirecting the user within the code (not needed since I am using Angular) when I should have been using the "ApiController" which returns an "IHttpActionResult" object which I can then translate using ".map(response => response.json())" correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With