1.0.6 • Published 4 years ago

ngx-mat-search-field v1.0.6

Weekly downloads
19
License
MIT
Repository
github
Last release
4 years ago

ngx-mat-search-field

npm npm

Angular 9 component providing an input field for searching.

Try it

Demo running at:

https://stackblitz.com/edit/ngx-mat-search-field-demo

Installation

npm i ngx-mat-search-field

API

import { SearchFieldModule } from 'ngx-mat-search-field' selector: ngx-mat-search-field

@Inputs()

InputTypeRequiredDescription
dataSourceobjectYESthe search field's source of data which is provided as a search-function
prefetchbooleanOptional, default: trueif true, it prefetches the data, if false, the data is fetched when the field gets focused
maxRowsnumberOptional, default: 8number of items in one fetch

Usage

Import the SearchFieldModule in your app.module.ts:

import { SearchFieldModule } from 'ngx-mat-search-field';

@NgModule({
  imports: [
    BrowserAnimationsModule,
    ReactiveFormsModule,
    SearchFieldModule
  ],
})
export class AppModule {}

Provide a DataSource that defines the search method:

import { SearchFieldDataSource, SearchFieldResult } from 'ngx-mat-search-field';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html'
})
export class AppComponent implements OnInit {

  searchFieldDataSource: SearchFieldDataSource;

  constructor(private userService: UserService) {
    this.searchFieldDataSource = {
      search(search: string, size: number, skip: number): Observable<SearchFieldResult> {
        return userService.getUsers(search, size, skip);
      }
    };
  }
}

Use it in your component:

<mat-form-field>
  <ngx-mat-search-field
    [dataSource]="searchFieldDataSource"
    placeholder="User"
  ></ngx-mat-search-field>
</mat-form-field>

Development

Development server

Run ng serve for a dev server to test the library. Navigate to http://localhost:4200/.

Build

Run npm run build-lib to build the search-field project. The build artifacts will be stored in the dist/ directory.

Build and NPM Package

Run npm run package to build and package the search-field project. The build artifacts will be stored in the dist/ directory.

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago