Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // PIPE
- import { Pipe, PipeTransform } from '@angular/core';
- @Pipe({
- name: 'filterByLabel'
- })
- export class FilterByLabelPipe implements PipeTransform {
- transform(items: any[], text: string): any {
- text = text.toLowerCase();
- return items.filter(item => {
- const findIndex = item.marca.toLowerCase().indexOf(text);
- return findIndex >= 0 ? true : false;
- });
- }
- }
- // home.page.ts
- import {Component, OnInit} from '@angular/core';
- @Component({
- selector: 'app-root',
- template: `
- <div >
- <ion-searchbar class="form-control" [(ngModel)]="textToSearch"></ion-searchbar>
- <li *ngFor="let item of lista| filterByLabel: textToSearch"
- class="list-group-item">
- {{item.marca}}
- </li>
- </div>
- `,
- })
- export class AppComponent {
- textToSearch = '';
- lista= [
- { marca: 'nokia'},
- { marca: 'samsung'},
- { marca: 'Iphone'},
- ];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement