如何清除ionic2中的所有列表
how to clear all list in ionic2
我在 ionic 2 项目中工作,创建了滑动以删除每个项目,工作正常,还需要单击按钮删除所有项目如何从 angular 2 中的列表中删除所有项目?
<button ion-button clear>Clear All</button>
<ion-item-sliding *ngFor="let note of notes">
<ion-item>
{{note.title}}
</ion-item>
<ion-item-options>
<button (click)="deleteNote(note)" danger>
<ion-icon name="trash"></ion-icon>
</button>
</ion-item-options>
</ion-item-sliding>
file.ts
constructor( public viewCtrl: ViewController ) {
this.notes = [
{ title: 'This is notification swipe to delete' },
{ title: 'This is notification swipe to delete' }
];
}
deleteNote(note){
let index = this.notes.indexOf(note);
if(index > -1){
this.notes.splice(index, 1);
}
}
您可以像这样创建一个 clear()
方法
public clear(): void {
this.notes = [];
}
并从视图中调用它
<button ion-button clear (click)="clear()">Clear All</button>
我在 ionic 2 项目中工作,创建了滑动以删除每个项目,工作正常,还需要单击按钮删除所有项目如何从 angular 2 中的列表中删除所有项目?
<button ion-button clear>Clear All</button>
<ion-item-sliding *ngFor="let note of notes">
<ion-item>
{{note.title}}
</ion-item>
<ion-item-options>
<button (click)="deleteNote(note)" danger>
<ion-icon name="trash"></ion-icon>
</button>
</ion-item-options>
</ion-item-sliding>
file.ts
constructor( public viewCtrl: ViewController ) {
this.notes = [
{ title: 'This is notification swipe to delete' },
{ title: 'This is notification swipe to delete' }
];
}
deleteNote(note){
let index = this.notes.indexOf(note);
if(index > -1){
this.notes.splice(index, 1);
}
}
您可以像这样创建一个 clear()
方法
public clear(): void {
this.notes = [];
}
并从视图中调用它
<button ion-button clear (click)="clear()">Clear All</button>