sridharan sridharan - 1 year ago 159
TypeScript Question

how to clear all list in ionic2

I'm working in ionic 2 project, created swipe to delete each items working fine and also need click button delete all items How can I delete all items from a list in angular 2?

<button ion-button clear>Clear All</button>
<ion-item-sliding *ngFor="let note of notes">
<button (click)="deleteNote(note)" danger>
<ion-icon name="trash"></ion-icon>


constructor( public viewCtrl: ViewController ) {
this.notes = [
{ title: 'This is notification swipe to delete' },
{ title: 'This is notification swipe to delete' }

let index = this.notes.indexOf(note);

if(index > -1){
this.notes.splice(index, 1);

Answer Source

You can create a clear() method like this

public clear(): void {
  this.notes = [];

And call it from the view

<button ion-button clear (click)="clear()">Clear All</button>  
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download