I expect *ngFor to iterate through the results of http.get which is made available via async pipe. Items are not being rendered, neither is the loading div.
Service:
public getKeywords = () => {
return this.http.get<getKeywords>(`${this.uri}/keywords`);
}
Interface:
interface getKeywords {
keywords: Array<object>;
}
TS:
export class KeywordsSettingsComponent implements OnInit {
public currentKeywords$: any;
constructor(private profileProvider: ProfileProvider) { }
ngOnInit() {
this.currentKeywords$ =
this.profileProvider.getKeywords().pipe(map(({ keywords }) => keywords));
}
}
Template:
<div class="row">
<ng-template *ngIf="currentKeywords$ | async as currentKeywords ; else loading">
<div class="keyword" * ngFor="let keywordObj of currentKeywords">
{{ keywordObj.keyword }}
<span class="icon-close"> </span>
</div>
</ng-template>
<ng-template #loading> Loading keywords...</ng-template>
</div>
The fact that the loading div is not displaying is indicated that a value isn't being emitted. If I subscribe in the ngOnInt like so:
this.currentKeywords$ = this.profileProvider.getKeywords().pipe(map(({keywords}) => keywords), share()).subscribe(res => res));
The loading div does show, but the result is not rendered in the *ngFor div. However I understand async pipe manages the subscriptions/unsubscribe, so subscribing in the ngOnInit should be unnecessary.
Result from http.get: The HTTP call returns an object which has several properties, one of which is "keywords" which contains an array of objects. I am using map() in order to map to a single property and access the array of objects.
{..."keywords":[{"id":331,"keyword":"spam"},{"id":330,"keyword":"foo"},{"id":332,"keyword":"brexit"}]}