import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { ConnectionProvider } from './../../providers/connection/connection';
import { DistrictProvider } from './../../providers/connection/district';



@Component({
  selector: 'page-search',
  templateUrl: 'search.html'
})
export class SearchPage {
    listOfSchools: any; 
    filterSchools: any;

  constructor(public navCtrl: NavController, public conn: ConnectionProvider, public dist: DistrictProvider) {
  }
    ngOnInit(): void {
        //Called after the constructor, initializing input properties, and the first call to ngOnChanges.
        //Add 'implements OnInit' to the class.
        this.dist.getAllSchools().subscribe(data => this.setData(data))
    }

    setData(data: any) {
        this.listOfSchools = this.dist.parseData(data);
        this.filterSchools = this.listOfSchools;
    }

    getSchool(event: any) {
        this.filterSchools = this.listOfSchools
        let val = event.target.value;

        if (val && val.trim() != '') {
            this.filterSchools = this.filterSchools.filter((item) => {
             return (item.name.toLowerCase().indexOf(val.toLowerCase()) > -1);
            });
        }

    }
}



    

  
  
