Compiled with problems:X
ERROR
src/app/components/users/users.component.html:2:22 - error TS2532: Object is possibly 'undefined'.
2 <ul *ngIf="loaded && users?.length > 0">
~~~~~~~~~~~~~~~~~
src/app/components/users/users.component.ts:6:16
6 templateUrl: './users.component.html',
~~~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component UsersComponent.
This is my error. I have been looking around whithout much luck. My experience with angular or typescript is very limited. I am actualy following a udemy course. This is the first time I am encountering "Optional Chaining" so I might be overlooking something obvious.
The code that produces the issue is fairly simple
<h2>Users</h2>
<ul *ngIf="loaded && users?.length > 0">
<li *ngFor="let user of users">
<h3>{{ user.firstName }} {{ user.lastName }}</h3>
<ul *ngIf="showExtended">
<li>age: {{ user.age }}</li>
<li>Address: {{ user.address.street }} {{ user.address.city }} {{ user.address.state }}</li>
</ul>
</li>
</ul>
The component.ts just provides a users[] But the coarse was trying to explain some sort of loading animation. Thats why the users[] sometimes is not loaded from the start.
Any help is appreciated.