gpt4 book ai didi

angular - ngc : Error: Return type of public method from exported class has or is using name 'Observable' from external module but cannot be named

转载 作者:太空狗 更新时间:2023-10-29 17:57:36 26 4
gpt4 key购买 nike

代码

this.store.select(state => state.user).subscribe(u => user = u).unsubscribe();

https://gist.github.com/nottinhill/eac309590096cc6f1b910f40a1b2f0c3 https://gist.github.com/nottinhill/5dc4026007a0c3ea3a4e0c15c0adfe05

错误

[02:25:41]  ngc: Error: Error at /Users/tyrion/devel/saveup-front/.tmp/+purchase/shared/purchase-service/purchase.service.ts:22:12: Return type of public method from exported class has or is using name 'Observable' from external module "/Users/tyrion/devel/saveup-front/node_modules/rxjs/Observable" but cannot be named.

问题

在这里强类型输入 Observable 的地方在哪里?到目前为止,我无法用它来编译它。

最佳答案

好吧,这有点奇怪,但我设法用服务内部的私有(private)方法修复了它:如果您正在使用 import {Http} from "@angular/http";,请确保放置 this.store.select(state => state.user) 方法的位置你在做这附近的事情:

import {Injectable} from '@angular/core';
import {Http, Response} from "@angular/http";
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import {Observable} from "rxjs";


@Injectable()
export class MyService {
static get parameters() {
return [[Http]];
}

constructor(private http: Http) {

}

getList() {
var url = 'http://<URL_HERE>';
var response = this.http.get(url).map(this.extractData).catch(this.handleError);

console.log(response);
return response;
}


private extractData(res: Response) {
let body = res.json();
return body || { };
}

private handleError (error: any) {
let errMsg = (error.message) ? error.message :
error.status ? `${error.status} - ${error.statusText}` : 'Server error';
console.error(errMsg); // log to console instead
return Observable.throw(errMsg);
}
}

我添加了这个方法 extractData 让它工作,如果你能提供你的服务会更好地找出问题。

关于angular - ngc : Error: Return type of public method from exported class has or is using name 'Observable' from external module but cannot be named,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39968759/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com