/ / In eckigen 2 Wie mache ich eine jsonp.request und wo importiere ich Jsonp aus - eckig

In eckigen 2 Wie mache ich eine jsonp.request und wo importiere ich Jsonp aus - eckig

In eckigen 2 Wie mache ich eine jsonp.request und wo importiere ich jsonp?

Ich benutze die neuesten eckigen2 Bibliotheken.

So habe ich es vor 6 Monaten gemacht, bevor ich ein Upgrade durchgeführt habe:

  this.jsonp.request(url, config).subscribe(response => {
this.blogArticles = response._body.response.posts;
});

Antworten:

2 für die Antwort № 1

https://angular.io/docs/ts/latest/guide/server-communication.html

import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { FormsModule } from "@angular/forms";
import { HttpModule, JsonpModule } from "@angular/http";

import { AppComponent } from "./app.component";

@NgModule({
imports: [
BrowserModule,
FormsModule,
HttpModule,
JsonpModule
],
declarations: [ AppComponent ],
bootstrap:    [ AppComponent ]
})
export class AppModule { }
class MyComponent {
constructor(private jsonp:Jsonp) {}

someMethod() {
this.jsonp.get(url).subscribe(...);
}
}

0 für die Antwort № 2

Sie können JsonpModule von @ angular / http wie folgt importieren:

import { HttpModule, JsonpModule } from "@angular/http";
...
@NgModule({
imports: [    BrowserModule,    FormsModule,    HttpModule,    JsonpModule ],
...

Und in der Komponente, benutze es so-

constructor(private jsonp:Jsonp) {}
...
this.jsonp.get(url).subscribe(...);
...