File

projects/ngx-list-view/src/lib/components/search/ngx-search.component.ts

Implements

OnInit

Metadata

selector ngx-search
styles :host { position: relative; display: block; } .search-clear { position: absolute; top: 7px; right: 8px; } a { cursor: pointer; }
templateUrl ngx-search.component.html

Index

Properties
Methods
Inputs

Inputs

debounceTime

Default value: 500

isCustom

Default value: false

placeholder

Default value: 'Search'

searchTerm

Type: EventEmitter

Default value: new EventEmitter()

target

Type: any

Methods

Public clearSearchTerm
clearSearchTerm(emit: boolean)
Parameters :
Name Type Optional Default value
emit boolean no false
Returns : void
ngOnInit
ngOnInit()
Returns : void

Properties

Public classes
classes: Array<string>
Type : Array<string>
Default value : ['form-control']
Public searchInputControl
searchInputControl: FormControl
Type : FormControl
Default value : new FormControl()
import {Component, Input, OnInit, EventEmitter, Output} from '@angular/core';
import {FormControl} from '@angular/forms';
import {debounceTime} from 'rxjs/operators';

@Component({
    selector: 'ngx-search',
    templateUrl: 'ngx-search.component.html',
    styles: [`
        :host {
            position: relative;
            display: block;
        }
        .search-clear {
            position: absolute;
            top: 7px;
            right: 8px;
        }
        a {
            cursor: pointer;
        }
    `]
})
export class NgxSearchComponent implements OnInit {

    @Output() @Input() public searchTerm = new EventEmitter();
    @Input() public placeholder = 'Search';
    @Input() public debounceTime = 500;
    @Input() public isCustom = false;
    public classes: Array<string> = ['form-control'];
    public searchInputControl: FormControl = new FormControl();
    @Input() public target: any;

    ngOnInit() {
        // Subscribe to and debounce form control, emitting search results
        this.searchInputControl
            .valueChanges
            .pipe(debounceTime(this.debounceTime))
            .subscribe((term: string) => {
                this.searchInputControl.setValue(term, { emitEvent: false });
                if (this.target) {
                    this.target.searchTerm.emit(term);
                } else {
                    this.searchTerm.emit(term);
                }
            });
    }

    public clearSearchTerm(emit: boolean = false) {
        this.searchInputControl.setValue('', {emitEvent: emit});
    }

}
<ng-template [ngIf]="isCustom">
    <ng-content></ng-content>
</ng-template>
<ng-template [ngIf]="!isCustom">
    <div class="form-group">
        <a (click)="clearSearchTerm(true)" class="search-clear">
            <i class="fa fa-times fa-1x"></i>
        </a>
        <input type="text" [ngClass]="classes"
               placeholder="Search"
               [formControl]="searchInputControl" />
    </div>
</ng-template>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""