Skip to content

Instantly share code, notes, and snippets.

@yoelnacho
Last active July 10, 2017 03:05
Show Gist options
  • Save yoelnacho/7d7c335dc6f89db7681208d89f5252d3 to your computer and use it in GitHub Desktop.
Save yoelnacho/7d7c335dc6f89db7681208d89f5252d3 to your computer and use it in GitHub Desktop.
Http get de tareas y filtro por atributo "important"
<p><strong>Importantes: </strong><span *ngIf="postsFilter">{{ postsFilter.length }}</span></p>
<ion-list>
<ion-item no-padding *ngFor="let post of posts">
<!-- {{ post.description }} -->
<span *ngFor="let item of post.tags">#{{ item.name }} </span>
</ion-item>
</ion-list>
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
posts: any;
postsFilter: any;
constructor(
public navCtrl: NavController,
public http: Http
) {
this.getData();
}
// get tasks
async getData(){
try {
this.http.get('http://service.dominio.com/task')
.map(res => res.json())
.subscribe(data => {
this.posts = data;
// filtro items con atributos important
this.postsFilter = this.posts.filter((filtro)=>{
return filtro.important == true;
});
});
} catch (e) {
console.error(e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment