我正在尝试扩展Angular 2中的Http服务来处理我需要在每个请求中包含的一些必需的头。我能够成功扩展它,添加我想要的标头,然后调用super.x()操作来发送请求。我使用this answer添加提供程序解决了这个问题 ,产生了这段代码:
ERROR in Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function (pos
ition 45:19 in the original .ts file), resolving symbol AppModule in [directory]/src/app/app.module.ts
我现在遇到编译错误:
providers: [
OAuthService,
{ provide: LoggerOptions, useValue: { level: environment.LogLevel }},
Logger,
{
provide: APIClient,
useFactory: apiClient,
deps: [XHRBackend, RequestOptions, OAuthService, Logger]
},
IdentityService
],
bootstrap: [AppComponent]
})
export class AppModule { }
export function apiClient(backend: XHRBackend, options: RequestOptions, oauthService: OAuthService, logger: Logger): APIClient {
return new APIClient(oauthService, backend, options, logger);
}
如何将我的扩展注入HTTP服务并解决此错误?
感谢。
更新 我能够使用以下代码编译应用程序:
final Intent i = new Intent(context, SingleItemView.class);
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(SchoolClass);
query.getInBackground(post.get(position).getObjectId(), new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
// TODO Auto-generated method stub
caption = object.getString("caption");
i.putExtra("Caption", caption);
Toast.makeText(context, caption, Toast.LENGTH_LONG).show();
}
});
Toast.makeText(context, caption, Toast.LENGTH_LONG).show();
context.startActivity(i);
但我不确定为什么我需要创建一个函数来包装我的API客户端的构造函数。我可以这样前进,但更愿意妥善解决这个问题。
答案 0 :(得分:1)
提前安装目标编译目前无法解析闭包(() =>
)。
另见https://github.com/qdouble/angular-webpack2-starter#aot--donts