When I retrieve a REST web service response, I can easily display it on the screen without any issues. However, the problem arises when the initial value of the web service call result is visible on the page. What steps should I take to render the page only after receiving a response from the web service? As of now, I am able to see the initial values of userInfo and userName. Below is a snippet of the code.
Regards, Alper
export class NavigationComponent implements OnInit {
response:any;
errorMessage:any;
form:FormGroup;
obj = {"one": "", "two": "", "three": "", "four": ""};
webserviceUrl = "https://httpbin.org/post";
webServiceUrlGet = "https://jsonplaceholder.typicode.com/posts/1";
username = "alper"
userInfo = "alper Info";
componentName = 'AppComponent';
ngOnInit():void {
this.getUserName();
}
getUserName() {
this.http.get(this.webServiceUrlGet)
.subscribe(
data => {
this.userInfo = data.json();
this.username = this.userInfo.userId;
},
error => this.errorMessage = error);
return this.username;
}
}