我正在创建一个Web API并使用Angular 2从服务器到客户端获取数据。但是发生以下错误。 (请参阅错误链接)
run
class ChartComponent {
models: Array<Model> = [];
constructor(public http: Http) {
this.getData();
}
getData() {
this.http.get('http://localhost:48512/api/data')
.map(res => (<Response>res).json())
.map((models: Array<any>) => {
let result: Array<Model> = [];
if (models) {
models.forEach(model => {
result.push(
new Model(
model.imageUrl,
model.question,
model.answer
));
});
}
return result;
}).
subscribe(
data => {
this.models = data;
console.log(this.models);
},
err => console.log(err)
);
}}
class Model {
constructor(
public imageUrl: string,
public question: string,
public answers: string) {
}}
}
答案 0 :(得分:0)
您需要以这种方式导入map
运算符:
import 'rxjs/Rx';
或
import 'rxjs/add/operator/map';
有关详细信息,请参阅此问题: