Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <p-dropdown #dd
- [options]="cars"
- [(ngModel)]="selectedCar"
- [style]="{'width':'100%'}"
- scrollHeight="400px"
- filter="true"
- filterBy="value,label"
- resetFilterOnHide="true"
- (onFocus)="OnFocus()"
- (keydown)="test($event)" >
- </p-dropdown>
- OnFocus() {
- if(this.cars.length > this.totalNumberOfCars) {
- this.cars.shift();
- }
- }
- test(event) {
- const charCode = event.keyCode;
- if(event.key === 'Enter') {
- this.selectedCar = this.cars.find(car => {
- return car.label.toLowerCase().includes(this.str.toLowerCase());
- });
- this.cars.unshift(this.selectedCar)
- this.str = '';
- } else if (event.key === 'Backspace') {
- this.str = this.str.replace(/.$/,"");
- } else if( (charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123) || charCode === 8) {
- console.log('here')
- this.str+= event.key;
- }
- }
Add Comment
Please, Sign In to add comment