-import {Directive, View, EventEmitter, ElementRef} from 'angular2/angular2';
+import {CORE_DIRECTIVES, Directive, View, EventEmitter, ElementRef} from 'angular2/angular2';
+import {Http} from 'angular2/http';
// RxJs
import * as Rx from '@reactivex/rxjs/dist/cjs/Rx';
@Directive({
selector: 'input[type=text][mou-live-search]',
outputs: ['results', 'loading'],
- providers: [SearchService]
+ providers: [CORE_DIRECTIVES, SearchService]
})
export class LiveSearch {
- results: EventEmitter = new EventEmitter();
- loading: EventEmitter = new EventEmitter();
+ results:EventEmitter = new EventEmitter();
+ loading:EventEmitter = new EventEmitter();
+
- constructor( private el: ElementRef, public search: SearchService){
+ constructor(private el:ElementRef, public http:Http, public search:SearchService) {
}
- onInit(){
+ onInit() {
console.log("starting");
(<any>Rx).Observable.fromEvent(this.el.nativeElement, 'keyup')
.map(e => e.target.value)
.flatMap(query => this.search.search(query))
.do(zone.bind(() => this.loading.next(false)))
.subscribe(
- zone.bind( orgunits => {
- console.log("orgunits: ");
- console.log(orgunits);
- //this.results.next(orgunits);
- this.results.next(orgunits);
+ zone.bind(orgunits => {
+ //this.filterUnits(orgunits)
+ this.results.next(orgunits/*this.filterUnits(orgunits)*/);
}),
zone.bind(err => {
console.log(err);