I start with Angular 2, starting with Angular 1, and I cannot figure out how to use ngFor for an attribute of an object.
this.myVardetermined by the result of the HTTP request that defines the attribute attr.
Here is my code:
import {Page} from 'ionic-angular';
import {MyService} from '../../services/my_service';
@Page({
templateUrl: 'build/pages/my_page/my_page.html',
providers: [MyService]
})
export class MyPage {
public myVar;
constructor(private myService: MyService) {
this.myService.fetch().subscribe(
data => this.myVar = data
);
}
}
<div *ngFor="#item of myVar.attr">
</div>
And this is a mistake:
EXCEPTION: TypeError: cannot read attr property from undefined in [myVar.attr in ...]
Thank!
akz92 source
share