]> git.uio.no Git - u/erikhf/frm.git/blobdiff - src/components/search/livesearch.ts
Fixed bugs where searchresult did not update, where searchlist got duplicated when...
[u/erikhf/frm.git] / src / components / search / livesearch.ts
index 96e7e7a82cc84767ebdfc73c7a34fa6343a0c22a..390a9035d8900e4dacff4773adb58d98eadd79ff 100644 (file)
@@ -1,4 +1,5 @@
-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';
@@ -10,17 +11,18 @@ declare var zone: Zone;
 @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)
@@ -31,11 +33,9 @@ export class LiveSearch {
             .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);