I have a service that gets the identity from an api as shown below.
getUserClaims() {
return this.http.get(this.rootUrl+'/api/GetUserClaims');
}
And in my home.component.ts I invoke it as follows.
userClaims: any;
ngOnInit() {
this.userService.getUserClaims().subscribe((data: any) => {
this.userClaims = data;
});
}
And I use the userClaims in the input element of the home.component.html like so:
<div class="col s12 m8 l9" >
<ul class="collapsible collapsible-accordion" data-collapsible="accordion">
<li>
<div class="collapsible-header active ">User Detail</div>
<div class="collapsible-body">
<div class="card ">
<br>
<div class="card-image" *ngIf="base64textString != null">
<img [src]="'data:image/jpg;base64,'+base64textString" style="padding-left: 20px; border-radius: 50%; width: 25%; height: 25%"/>
</div>
<div class="card-content">
<table>
<tbody>
<tr>
<td><span style="font-weight:bold;">UserId </span></td>
<td>
<div class="input-field">
<input [disabled]="disabledInput" value="{{userClaims.UserId}}" type="text" class="validate">
</div>
</td>
</tr>
<tr>
<td><span style="font-weight:bold;">Username </span></td>
<td>
<div class="input-field">
<input [disabled]="disabledInput" value="{{userClaims.UserName}}" type="text" class="validate">
</div>
</td>
</tr> .........
When I log in, I get the following error:
ERROR TypeError: Cannot read property 'UserId' of undefined
And my inputs do not show. But when I refresh, that's the time when my input elements gets populated but the error still persists in the devconsole.
Any pointers in this regard will be appreciated.