I have the following code:
HTML
<div *ngIf="users">
<ul>
<li *ngFor="let user of users">{{ user.name }}</li>
</ul>
</div>
TS FILE
export class AppComponent implements OnInit {
constructor(private http: HttpClient) {};
users: any;
ngOnInit() {
this.subscription = this.http.get('https://jsonplaceholder.typicode.com/users').subscribe(users => {
this.users = users;
})
}
ngOnDestroy() {
this.subscription.unsubscribe();
}
}
i want to avoid manually unsubscribing and want to use async. How can i convert this to work with async pipe because when i try
<li *ngFor="let user of users | async">{{ user.name }}</li>
i get
Error: InvalidPipeArgument: '[object Object],[object Object],[object Object],