Commit 593bc5fd authored by Sebastian's avatar Sebastian

autosuggest

parent 787ccec7
......@@ -25,9 +25,11 @@
<!-- search field -->
<!-- <app-autosuggest (termChanged)="termChanged(term)"></app-autosuggest> -->
<!-- old search input -->
<!--
<input type="text" formControlName="searchPattern"
class="form-control searchinput" placeholder="Wie heißt dein Ort?" />
-->
<app-autosuggest formControlName="searchPattern"></app-autosuggest>
<!-- old search button
<div class="input-group-append">
<button (click)="search()"
......
......@@ -311,6 +311,7 @@ search(){
if(pattern.length < 3){
return;
}
this.logger.debug("Searching for "+JSON.stringify(this.searchForm.value.searchPattern));
this.hasResults = false;
//this.spinner.show();
this.apiService.searchGeoElements(this.searchForm.value.searchPattern).subscribe((response)=>{this.parseSearchResult(response);},(error)=>{this.parseError(error);});
......
......@@ -6,4 +6,4 @@
</ng-template>
<input id="typeahead-template" type="text" class="form-control searchinput" [(ngModel)]="model" [ngbTypeahead]="search" [resultTemplate]="rt"
[inputFormatter]="formatter" placeholder="Wie heißt dein Ort?" formControlName="searchPattern"/>
[inputFormatter]="formatter" placeholder="Wie heißt dein Ort?"/>
import {Component, OnInit, Output, EventEmitter} from '@angular/core';
import {Component, OnInit, OnChanges, Output, EventEmitter,forwardRef } from '@angular/core';
import {Observable, empty} from 'rxjs';
import {debounceTime, distinctUntilChanged, map, switchMap, catchError} from 'rxjs/operators';
import { GeoportalApiService } from '../../services/geoportal-api.service';
import { ControlValueAccessor,DefaultValueAccessor,NG_VALUE_ACCESSOR } from '@angular/forms';
......@@ -11,18 +11,57 @@ import { GeoportalApiService } from '../../services/geoportal-api.service';
@Component({
selector: 'app-autosuggest',
templateUrl: './autosuggest.component.html',
styleUrls: ['./autosuggest.component.css']
styleUrls: ['./autosuggest.component.css'],
providers: [
{
provide: NG_VALUE_ACCESSOR,
multi: true,
useExisting: forwardRef(() => AutosuggestComponent),
}
]
})
export class AutosuggestComponent implements OnInit {
export class AutosuggestComponent implements OnInit, ControlValueAccessor, OnChanges {
@Output() term: EventEmitter<string> = new EventEmitter<string>();
public model: any;
public _model: any;
public touched = false;
constructor(private apiService: GeoportalApiService) {
}
onChange = (delta: any) => {};
onTouched = () => {
this.touched = true;
};
public writeValue(delta: any): void {
this.model = delta;
this.onChange(delta);
}
public registerOnChange(fn: (v: any) => void): void {
this.onChange = fn;
}
public registerOnTouched(fn: () => void): void {
this.onTouched = fn;
}
get model() {
console.log("reading model.");
return this._model;
}
set model(val) {
this._model = val;
if( typeof val == "string"){
this.onChange(this._model);
}else{
this.onChange(this._model.name);
}
}
ngOnChanges(){
}
ngOnInit() {
}
......@@ -30,7 +69,7 @@ export class AutosuggestComponent implements OnInit {
let lst=[];
return text$.pipe(
debounceTime(200),
debounceTime(50),
distinctUntilChanged(),
switchMap( (searchText) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment