Advertisement
AndreaTU

Untitled

Sep 5th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. // PIPE
  2. import { Pipe, PipeTransform } from '@angular/core';
  3.  
  4. @Pipe({
  5. name: 'filterByLabel'
  6. })
  7. export class FilterByLabelPipe implements PipeTransform {
  8.  
  9. transform(items: any[], text: string): any {
  10. text = text.toLowerCase();
  11. return items.filter(item => {
  12. const findIndex = item.marca.toLowerCase().indexOf(text);
  13. return findIndex >= 0 ? true : false;
  14. });
  15. }
  16.  
  17. }
  18.  
  19.  
  20.  
  21. // home.page.ts
  22.  
  23. import {Component, OnInit} from '@angular/core';
  24.  
  25. @Component({
  26. selector: 'app-root',
  27. template: `
  28. <div >
  29. <ion-searchbar class="form-control" [(ngModel)]="textToSearch"></ion-searchbar>
  30.  
  31.  
  32. <li *ngFor="let item of lista| filterByLabel: textToSearch"
  33. class="list-group-item">
  34. {{item.marca}}
  35.  
  36. </li>
  37. </div>
  38. `,
  39. })
  40. export class AppComponent {
  41. textToSearch = '';
  42.  
  43. lista= [
  44. { marca: 'nokia'},
  45. { marca: 'samsung'},
  46. { marca: 'Iphone'},
  47. ];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement