我在离子2项目中工作,创建了滑动以删除每个工作正常的项目,还需要单击按钮删除所有项目如何从角度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);
}
}
答案 0 :(得分:3)
您可以像这样创建clear()
方法
public clear(): void {
this.notes = [];
}
从视图中调用
<button ion-button clear (click)="clear()">Clear All</button>