I'm trying to display a list of Contacts in a list:
<h1>Contacts</h1>
<ul>
<li *ngFor="let contact of contacts$ | async">
<ul>
<h1>Name: {{contact.name}}</h1>
<li>ObjectID: {{contact._id}}</li>
<li>LastName: {{contact.lastName}}</li>
<li>FirstName: {{contact.firstName}}</li>
<li>Email: {{contact.email}}</li>
<li>Notes:
<ul *ngFor="let note of contact.notes">
<li>{{note}}</li>
</ul>
</li>
</ul>
</li>
</ul>
contacts$ is an Observable<Array<Object>>:
@Component({
selector: 'contacts-list',
templateUrl: 'list.component.html'
})
export class ContactsListComponent implements OnInit {
contacts$: Observable<Array<Object>>;
constructor(private logger: LoggerService,
private router: Router,
private trackerService: TrackerService) {
this.logger.debug(`ContactListComponent.ctor`);
}
ngOnInit() {
this.contacts$ = this.trackerService.cache('tracker/contacts');
}
}
For now, TrackerService.cache(...) is simply creating an Observable froma hardcoded array, for testing:
public cache(path: string): Observable<Array<Object>> {
let retval = [new Object({
_id: '123abc',
lastName: 'last',
firstName: 'first',
email: '[email protected]',
notes: ['note 1', 'note 2']
}), new Object({
_id: '123abc',
lastName: 'last',
firstName: 'first',
email: '[email protected]',
notes: ['note 1', 'note 2']
})];
return Observable.from(retval)
.map((v) => {
this.logger.debug(`Mapping value: ${JSON.stringify(v)}`);
return v;
});
}
The .map() operation is just for testing, and I see this in the chrome console:
debug DEBUG: Mapping value: {"_id":"123abc","lastName":"last","firstName":"first","email":"[email protected]","notes":["note 1","note 2"]}
However when I run this, I'm getting:
Error: Error in ./ContactsListComponent class ContactsListComponent - inline template:2:8 caused by: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
I've read other SO threads, angular.io, and my ng2-book which has similar examples, but I'm just not figuring this out.
What am I doing wrong?
mapcall, but I do the template is not rendered.