Ce code fonctionne sur angular2 v.2.0.0 .rc.2 mais does't sur angular2 v2.0.1rxjs angular2 .map travail does't dans la version 2.0.1
app.appcomponent.ts
import { Component, OnInit } from "@angular/core";
import { Injectable } from '@angular/core';
import { Http, Response, URLSearchParams } from "@angular/http";
import { IFood } from "./food";
import { Headers, RequestOptions } from "@angular/http";
Je peux importer ceci pour l'utilisation .map droit?
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/toPromise';
import 'rxjs/add/operator/catch';
@Component({
selector: "my-app",
template: `
<h1>My First Angular 2 App</h1>
<ul *ngFor='let food of foods'>
<li>{{food.foodName}}</li>
</ul>
`,
templateUrl: "./app/form.html"
})
@Injectable()
export class AppComponent implements OnInit {
public values: string[];
public headers: Headers;
errorMessage: string;
J'ai une liste de nourriture dans mon contrôleur, foodid, foodname
foods: IFood[];
foodModel = <IFood>{};
constructor(private http: Http) {
this.http = http;
this.headers = new Headers();
this.headers.append("Content-Type", "application/json");
}
ngOnInit() {
return this.http.get("/home/getdata")
il y a .map travail does't, ne pouvons-nous utiliser .map dans angular2 2.0.1?
.map((response: Response) => <IFood[]>response.json())
.subscribe(data => this.foods = data, error =>
this.errorMessage = <any>error);
}
}
Dois-je créer des services? Comment résoudre ce problème, merci
Essayez avec ' « importation rxjs/Rx'' il charge tous les symboles. – micronyks
Je suis essayer mais ne fonctionne pas. l'alerte 'map' n'existe pas sur le type 'Observable' –
Essayez de l'importer avant Observable, ou mieux encore, déplacez l'opérateur vers la racine NgModule. – Sasxa