我将angular-cli更新为v22-1,只想测试我的http.service
我收到此错误:
ERROR in ./src/app/app.module.ngfactory.ts
Module build failed: Error: C:/Users/e/WebstormProjects/servicyz/src/app/http.service.ts (9,3): Return type of public method from exported class has or is using name 'Observable' from external module "C:/Users/e/WebstormProjects/serv
icyz/node_modules/rxjs/Observable" but cannot be named.)
C:/Users/e/WebstormProjects/servicyz/src/app/http.service.ts (9,3): Return type of public method from exported class has or is using name 'Response' from external module "C:/Users/e/WebstormProjects/servicyz/node_modules/@angular/htt
p/src/static_response" but cannot be named.)
为什么?我在http.service.ts
数组中导入app.module.ts
内的providers[]
;我的HttpService类的内容是:
import { Injectable } from '@angular/core';
import {Http} from "@angular/http";
@Injectable()
export class HttpService {
constructor(private http:Http) {}
getData(){
return this.http.get("https://example.com/title.json")
}
}
需要我总是创建ngModule并导出我的类,然后在app.module.ts中的imports []中添加它吗?为什么我不能简单地在提供商内部导入我的服务?这是什么意思:
Return type of public method from exported class has or is using name 'Observable' from external module "
这是否意味着我已经在app.module.ts中使用了Observable?有人可以在这里指导我,谢谢。
我juste像这样getData():Observable<any>{...}
添加Observable返回,一切正常!有人可以解释一下为什么这种行为?为什么我需要写这个返回类型?