62 lines
1.4 KiB
TypeScript
62 lines
1.4 KiB
TypeScript
import { Component, OnInit,Input, Output, EventEmitter} from '@angular/core';
|
|
import { FormGroup, Validators } from '@angular/forms';
|
|
|
|
import { ServerService } from '../../../services/server.service';
|
|
import { UUID } from 'angular2-uuid';
|
|
import { NguiAutoCompleteModule } from '@ngui/auto-complete';
|
|
|
|
declare var $: any;
|
|
|
|
|
|
@Component({
|
|
selector: 'autocomplete-remote',
|
|
templateUrl: './autocomplete-remote.component.html',
|
|
styleUrls: ['./autocomplete-remote.component.css']
|
|
})
|
|
|
|
export class AutocompleteRemoteComponent implements OnInit {
|
|
|
|
constructor(private serverService :ServerService) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Input() id : string = UUID.UUID();
|
|
@Input() label : string;
|
|
@Input() url : string;
|
|
@Input() formCtrlName : string;
|
|
@Input() form: FormGroup;
|
|
|
|
|
|
selectedValue : string;
|
|
//@Output() selectedValueEmitter: EventEmitter<string> = new EventEmitter<string>();
|
|
|
|
values : any[] = new Array();
|
|
|
|
query : string = "";
|
|
|
|
ngOnInit() {
|
|
this.updateByQuery(this.query); //just to trigger the first call
|
|
}
|
|
|
|
|
|
|
|
updateByQuery(query : string){
|
|
//this.selectedValueEmitter.next(this.selectedValue);
|
|
this.serverService.getThroughProxy(this.url, query).subscribe(
|
|
response => {
|
|
this.values.length = 0; //clear array; -- this is quite a fast and memory efficient way
|
|
response.data.forEach(element => {
|
|
this.values.push(element.attributes.name);
|
|
});
|
|
},
|
|
error => {
|
|
console.log(error);
|
|
}
|
|
);
|
|
}
|
|
|
|
|
|
}
|