Last active
July 10, 2017 03:05
-
-
Save yoelnacho/7d7c335dc6f89db7681208d89f5252d3 to your computer and use it in GitHub Desktop.
Http get de tareas y filtro por atributo "important"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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