Initial search as you type capability

Refs #173
This commit is contained in:
Will Abson
2016-06-09 13:09:07 +01:00
parent c713799445
commit 914ad910b7
4 changed files with 125 additions and 2 deletions

View File

@@ -17,10 +17,11 @@
import { Control, Validators } from 'angular2/common';
import { Component, Input, Output, EventEmitter, AfterViewInit } from 'angular2/core';
import { AlfrescoService } from './../services/alfresco.service';
import { AlfrescoPipeTranslate, AlfrescoTranslationService } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
import { AlfrescoSearchAutocompleteComponent } from './alfresco-search-autocomplete.component';
declare let __moduleName: string;
declare var componentHandler: any;
@@ -30,7 +31,7 @@ declare var componentHandler: any;
styles: [
],
templateUrl: './alfresco-search-control.component.html',
providers: [AlfrescoService],
directives: [AlfrescoSearchAutocompleteComponent],
pipes: [AlfrescoPipeTranslate]
})
export class AlfrescoSearchControlComponent implements AfterViewInit {
@@ -52,6 +53,9 @@ export class AlfrescoSearchControlComponent implements AfterViewInit {
searchControl: Control;
@Input()
autocompleteSearchTerm = '';
constructor(private translate: AlfrescoTranslationService) {
this.searchControl = new Control(
@@ -59,6 +63,12 @@ export class AlfrescoSearchControlComponent implements AfterViewInit {
Validators.compose([Validators.required, Validators.minLength(3)])
);
this.searchControl.valueChanges.debounceTime(400).distinctUntilChanged().subscribe(
(value: string) => {
this.autocompleteSearchTerm = value;
}
);
translate.addTranslationFolder('node_modules/ng2-alfresco-search');
}