2017-07-13 7 views
2

これを行う方法がわかりません。私はインターネットからいくつかの例を試しました。最高の解決策は何ですか?URLのjsonからデータを取得しているイオニックアプリ

import { Component } from '@angular/core'; 

@Component({ 
    selector: 'page-hello-ionic', 
    templateUrl: 'hello-ionic.html' 
}) 
export class HelloIonicPage { 
    constructor() { 

    } 
} 

答えて

1

この

はSRC /アプリ/ app.module.tsを変更し、

import { HttpModule } from '@angular/http'; 

をインポート、輸入、使用することができます。その後

@NgModule({ 
    declarations: [ 
    MyApp, 
    HomePage 
    ], 
    imports: [ 
    BrowserModule, 
    HttpModule, 
    IonicModule.forRoot(MyApp) 
    ], 
    bootstrap: [IonicApp], 
    entryComponents: [ 
    MyApp, 
    HomePage 
    ], 
    providers: [ 
    StatusBar, 
    SplashScreen, 
    {provide: ErrorHandler, useClass: IonicErrorHandler} 
    ] 
}) 
export class AppModule {} 

に追加行うにはHTTPモジュールからの角度。あなたのPage.tsで

インポートモジュールとさらにあなたはJSONオブジェクト

var jsonobject = JSON.parse(data) 

に戻っJSON文字列に変換することができ、この

import { Http } from '@angular/http'; 

constructor(public navCtrl: NavController, public http: Http) { 

    let url = "https://www.reddit.com/r/gifs/new/.json?limit=10"; 

    this.http.get(url).map(res => res.json()).subscribe(data => { 

     console.log(data); 

    }); 

    } 

のようにそれを使用して、代わりにあなたができますIONIC NATIVE HTTP PLUGIN

乾杯:D

+0

ありがとうございます。私はあなたを愛し、ホモはありません:) – adrian

+0

心配しなくても、大いに愛:D –

関連する問題