Javascript Angular2 Http POST引发订阅服务器异常

Javascript Angular2 Http POST引发订阅服务器异常,javascript,angular,angular2-services,Javascript,Angular,Angular2 Services,我在Angular 2应用程序中有以下文件: 可注入服务 @Injectable() export class CompanyService{ constructor(private http:Http){} public test():any{ return this.http.get('http://echo.jsontest.com/title/ipsum/content/blah') .map(res => res.json()

我在Angular 2应用程序中有以下文件:

可注入服务

@Injectable()  
export class CompanyService{
    constructor(private http:Http){}

    public test():any{
        return this.http.get('http://echo.jsontest.com/title/ipsum/content/blah')
        .map(res => res.json())
        .catch((error:any) => Observable.throw(error.json().error || 'Server error'));
    }
}
public test():Observable<any>{
    return this.http.get('http://echo.jsontest.com/title/ipsum/content/blah')
           .map(res => res.json())
           .catch((error:any) => Observable.throw(error.json().error || 'Server error'));
}
组件

@Component({
    templateUrl: 'company.html',
    providers: [CompanyService]
})
export class CompanyPage{
    constructor(private companyServ:CompanyService){}

    //This method is used from a submit for using ngSubmit
    public onSubmit():void{
        this.companyServ.test().subscribe(data => {
            console.log('Data', data);
        }, err => {
            console.error('Error', err);
        }, console.log('End'));
    }
}
当呈现视图并调用方法
onSubmit
时,我得到以下错误:


非常感谢提供有关错误的任何信息。

解决方案是更改返回类
CompanyService
test()
方法的数据类型:

可注入服务

@Injectable()  
export class CompanyService{
    constructor(private http:Http){}

    public test():any{
        return this.http.get('http://echo.jsontest.com/title/ipsum/content/blah')
        .map(res => res.json())
        .catch((error:any) => Observable.throw(error.json().error || 'Server error'));
    }
}
public test():Observable<any>{
    return this.http.get('http://echo.jsontest.com/title/ipsum/content/blah')
           .map(res => res.json())
           .catch((error:any) => Observable.throw(error.json().error || 'Server error'));
}