Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Iteration2
  • Loading branch information
AlvaroCSinnocv committed Apr 3, 2019
commit 5b64224d5e7a442015341983d10307ac3cd78997
2 changes: 1 addition & 1 deletion starter-code/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import { Component } from '@angular/core';
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app works!';
title = 'Disfruta de nuestra App!!!';
}
2 changes: 2 additions & 0 deletions starter-code/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { HttpModule } from '@angular/http';

import { AppComponent } from './app.component';
import { FoodListComponent } from './food-list/food-list.component';
import { FilterPipe } from './food-list/filter.pipe';

@NgModule({
declarations: [
AppComponent,
FoodListComponent,
FilterPipe,
],
imports: [
BrowserModule,
Expand Down
8 changes: 8 additions & 0 deletions starter-code/src/app/food-list/filter.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { FilterPipe } from './filter.pipe';

describe('FilterPipe', () => {
it('create an instance', () => {
const pipe = new FilterPipe();
expect(pipe).toBeTruthy();
});
});
20 changes: 20 additions & 0 deletions starter-code/src/app/food-list/filter.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
name: 'filter'
})
export class FilterPipe implements PipeTransform {

transform(items: any[], field: string, value: string): any[] {
if (!items) {
return [];
}

if (!value) {
return items;
}

const myPattern = new RegExp(value, 'i');
return items.filter(it => it[field].match(myPattern));
}
}
27 changes: 19 additions & 8 deletions starter-code/src/app/food-list/food-list.component.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
<h1>
Esto es la lista de comida
</h1>
<div *ngFor="let food of foods" >
<h3>Food name:{{food.name}}</h3>
<img [src]="food.image" height='40px' />
<p>Calories: {{food.calories}}</p>
<p>Quantity: {{food.quantity}} </p>
<h2>
Usa nuestra lista de comida
</h2>

<!-- <input type="text" placeholder="Buscar" > -->

<div>
<label for="things_name"> Busqueda de comida </label>
<input id="food_name" placeholder="food data" type="text" [(ngModel)]="pattern">
<div>

<h3> Comida encontrada </h3>


<div *ngFor="let food of foods| filter:'name':pattern">
<h3>Food name:{{food.name}}</h3>
<img [src]="food.image" height='40px' />
<p>Calories: {{food.calories}}</p>
<p>Quantity: {{food.quantity}} </p>
</div>
1 change: 1 addition & 0 deletions starter-code/src/app/food-list/food-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import foods from '../foods';
export class FoodListComponent implements OnInit {

foods:Object[];


constructor() {
this.foods = foods;
Expand Down