Reputation: 11
guys. Im pretty much a begginer in ionic 2 and Im trying to build a simple app able to read strings from a JSON file. I have doubts how my ts file should be. I ve seen some examples here in stack overflow but no one ever sais where to paste the code the reply. So, can someone help me with the correct code (imports and comands) SO i can display a string in the screen to the user.
My ts file
import { Component } from '@angular/core';
import { NavController, LoadingController } from 'ionic-angular';
import {HttpProvider} from '../../providers/http-provider';
//@Component({
//selector: 'page-favorite',
//templateUrl: 'favorite.html'
//})
@Component({
selector: 'page-favorito',
templateUrl: 'favorito.html',
providers:[HttpProvider]
})
export class Favorito {
jsonData: any;
loading: any;
constructor(public navCtrl: NavController, private
httpProvider:HttpProvider,public loadingCtrl: LoadingController) {
}
}
My HTML code:
<ion-header>
<ion-navbar>
<button ion-button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-title>Favoritos</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<ion-list>
<ion-item *ngFor="let feed of feeds">
{{feed.data.title}}
</ion-item>
</ion-list>
</ion-content>
Upvotes: 0
Views: 1207
Reputation: 653
you can use ur json path with http request
this.http.get(this.jsonPath)
.map(res => res.json())
.subscribe(data => {
//do the needful stuff with the data
});
for this you need to
import { Http, URLSearchParams, Response, Headers, RequestOptions } from '@angular/http';
and in the constructor you need to create an instance
constructor(public http: Http) {
//call the http method here
}
Upvotes: 1