Search functional issue


#1

when i clear the search box it still showin the only search value.my previous list item is not showing

i want to do like that Please click here.
here is my full code how can i do that please suggest me.

items:any[] = [];
mydata: any;

  constructor(public navCtrl: NavController, public navParams: NavParams, public http: Http) {

   
  //start auto load
 let self = this;
  setInterval(function () {
    self.items;
  }, 300); 
  //end
  }


 ngOnInit() {
    this.setItems();
  }

  setItems() {
    this.items = this.items;
  }

  filterItems(ev: any) {
    this.setItems();
    let val = ev.target.value;

      if (val && val.trim() !== '') {
      this.items = this.items.filter(function(item) {
        return item.userName.toLowerCase().includes(val.toLowerCase());
      });
    }
  }  
  ionViewDidLoad() {
   var headers = new Headers();
    headers.append('Content-Type', 'application/x-www-form-urlencoded');
    let options = new RequestOptions({ headers: headers });

     this.http.get(url+"/leadlistingusers")
     
      .subscribe((res:Response)=>{
      let dataTemp = res.json(); //dataTemp is the json object you showed me
      this.mydata = dataTemp.viewleadusers; //contains a [] object with all yours user
      for(let i = 0; i < this.mydata.length; i++){
           
            let a = this.mydata[i].userName;
            let b= this.mydata[i].userID;
            alert(b);
            alert(a);
            this.items.push({
               "userID": b,
               "userName":a
            })      
       }
  })
   
 };

#2

There is much to say about this code

I will say these things

Dont use function but the fat arrow syntax to preserve context: ()=>{}

SetItems function does nothing or at least not what you probably intend. You probably need a loadedList and a filteredList variable.

And the self.items; in the interval also doesnt do anything usefull I would say. It is not a function call

Next, you can replace the for loop with a .map(value=>{…}) which is easier to reas and less bug sensitive

And so on…