ngx-deep-search
Version:
**Compatibility:**
99 lines (92 loc) • 5.97 kB
JavaScript
import * as i0 from '@angular/core';
import { Injectable, EventEmitter, Component, Input, Output, NgModule } from '@angular/core';
class NgxDeepSearchService {
constructor() { }
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.2.2", ngImport: i0, type: NgxDeepSearchService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.2.2", ngImport: i0, type: NgxDeepSearchService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.2", ngImport: i0, type: NgxDeepSearchService, decorators: [{
type: Injectable,
args: [{
providedIn: 'root'
}]
}], ctorParameters: () => [] });
class NgxDeepSearchComponent {
constructor() {
this.placeholder = 'Search';
this.searchFromKeys = [];
this.dataList = [];
this.resultedData = new EventEmitter();
this.filteredData = [];
}
ngOnInit() {
}
onValueChange(event) {
const p = event.target;
const filterd = this.search(p.value);
this.resultedData.emit(filterd);
}
search(searchValue) {
const filteredData = [];
for (let i = 0; i < this.dataList.length; i++) {
const product = this.dataList[i];
let productProperties = this.searchFromKeys.map((key) => product[key]).join(',').toLowerCase();
productProperties = productProperties.replace(/undefined/g, '');
const searchQuery = searchValue.toLowerCase();
const andOption = [];
let stringArray2 = searchQuery.split(' ');
if (stringArray2.length > 0) {
stringArray2 = stringArray2.filter((i) => i != '');
stringArray2.forEach((i) => {
if (productProperties.indexOf(i) > -1 && i != '') {
andOption.push('true');
}
else {
andOption.push('false');
}
});
}
if (!andOption.includes('false')) {
filteredData.push(product);
}
}
return filteredData;
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.2.2", ngImport: i0, type: NgxDeepSearchComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.2.2", type: NgxDeepSearchComponent, selector: "ngx-deep-search", inputs: { placeholder: "placeholder", searchFromKeys: "searchFromKeys", dataList: "dataList" }, outputs: { resultedData: "resultedData" }, ngImport: i0, template: "<div class=\"input-container\">\r\n <input type=\"text\" id=\"search-input\" (input)=\"onValueChange($event)\" required=\"\" />\r\n <label>{{placeholder}}</label>\t\t\r\n</div>\r\n\r\n", styles: [".input-container{position:relative;margin-bottom:25px}.input-container label{position:absolute;top:0;left:0;font-size:16px;color:#555;pointer-events:none;transition:all .5s ease-in-out}.input-container input{border:0;border-bottom:1px solid #555;background:transparent;width:100%;padding:8px 0 5px;font-size:16px;color:#555}.input-container input:focus{border:none;outline:none;border-bottom:1px solid #0000FF}.input-container input:focus~label,.input-container input:valid~label{top:-12px;font-size:12px}\n"] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.2", ngImport: i0, type: NgxDeepSearchComponent, decorators: [{
type: Component,
args: [{ selector: 'ngx-deep-search', template: "<div class=\"input-container\">\r\n <input type=\"text\" id=\"search-input\" (input)=\"onValueChange($event)\" required=\"\" />\r\n <label>{{placeholder}}</label>\t\t\r\n</div>\r\n\r\n", styles: [".input-container{position:relative;margin-bottom:25px}.input-container label{position:absolute;top:0;left:0;font-size:16px;color:#555;pointer-events:none;transition:all .5s ease-in-out}.input-container input{border:0;border-bottom:1px solid #555;background:transparent;width:100%;padding:8px 0 5px;font-size:16px;color:#555}.input-container input:focus{border:none;outline:none;border-bottom:1px solid #0000FF}.input-container input:focus~label,.input-container input:valid~label{top:-12px;font-size:12px}\n"] }]
}], ctorParameters: () => [], propDecorators: { placeholder: [{
type: Input
}], searchFromKeys: [{
type: Input
}], dataList: [{
type: Input
}], resultedData: [{
type: Output
}] } });
class NgxDeepSearchModule {
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.2.2", ngImport: i0, type: NgxDeepSearchModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.2.2", ngImport: i0, type: NgxDeepSearchModule, declarations: [NgxDeepSearchComponent], exports: [NgxDeepSearchComponent] }); }
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.2.2", ngImport: i0, type: NgxDeepSearchModule }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.2", ngImport: i0, type: NgxDeepSearchModule, decorators: [{
type: NgModule,
args: [{
declarations: [
NgxDeepSearchComponent
],
imports: [],
exports: [NgxDeepSearchComponent]
}]
}] });
/*
* Public API Surface of ngx-deep-search
*/
/**
* Generated bundle index. Do not edit.
*/
export { NgxDeepSearchComponent, NgxDeepSearchModule, NgxDeepSearchService };
//# sourceMappingURL=ngx-deep-search.mjs.map