Hi everyone,
i want to build my first app but my list dont want to show.
Please help
import { Component } from '@angular/core';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
public items;
ionViewDidLoad(): string{
this.items = [
{title: 'Notatka 1', description: 'Opis notatki 1'},
{title: 'Notatka 2', description: 'Opis notatki 2'},
{title: 'Notatka 3', description: 'Opis notatki 3'}
];
return this.items;
}
}
<ion-content>
<ion-list padding>
<ion-item *ngFor="let item of items" (click)="viewItem(item)">{{item.title}}<p>{{item.description}}</p></ion-item>
</ion-list>
</ion-content>
try this:
import { Component } from '@angular/core';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
public items: Array<any>;
ionViewDidLoad() {
this.items = [
{ title: 'Notatka 1', description: 'Opis notatki 1' },
{ title: 'Notatka 2', description: 'Opis notatki 2' },
{ title: 'Notatka 3', description: 'Opis notatki 3' }
];
}
}
<ion-content>
<ion-list padding *ngFor="let item of items">
<ion-item (click)="viewItem(item)">
{{item.title}}
<p>{{item.description}}</p>
</ion-item>
</ion-list>
</ion-content>
I hope solve.
Always initialize any property that is referenced by a template to a sane value. For objects, that means at least {}
, and for arrays, at least []
. Also give it a proper type. Do not abuse any
as suggested earlier.
Hello,
look here there is a good example