sri*_*ran 1 typescript ionic-framework ionic2 ionic3 angular
我在 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>
Run Code Online (Sandbox Code Playgroud)
文件.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);
}
}
Run Code Online (Sandbox Code Playgroud)
您可以创建这样的clear()
方法
public clear(): void {
this.notes = [];
}
Run Code Online (Sandbox Code Playgroud)
并从视图中调用它
<button ion-button clear (click)="clear()">Clear All</button>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3766 次 |
最近记录: |