导入后BaseRequestOptions angular2错误 [英] BaseRequestOptions angular2 error after import

查看:101
本文介绍了导入后BaseRequestOptions angular2错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用angular2项目,但我是angular2中的新手。我做完后出现问题

I'm working with angular2 project, but im new in angular2. I have a problem after i do

import { BaseRequestOptions } from '@angular/http';
providers: [
...
..,BaseRequestOptions 
]

错误是:


对象{__zone_symbol__error:错误,fileName:Getter,lineNumber:
Getter, columnNumber:Getter,message:getter,name:Getter,stack:
Getter,originalStack:Getter,zoneAwareStack:Getter,toString:
createMethodProperty / props [key] .value(),3 more ...}

Object { __zone_symbol__error: Error, fileName: Getter, lineNumber: Getter, columnNumber: Getter, message: Getter, name: Getter, stack: Getter, originalStack: Getter, zoneAwareStack: Getter, toString: createMethodProperty/props[key].value(), 3 more… }

出了什么问题?

推荐答案

这仍然是Angular的实验阶段

This is still in Experimental Phase of Angular.

您需要使用 BaseRequestOptions 并创建自定义选项,以便将它们注入提供者列表下的请求选项

You need to use the BaseRequestOptions and create your custom options, so that you can inject them into request options under your providers list

使用如下,
导入以下

Use as below, Import the below

import {HTTP_BINDINGS, Http, BaseRequestOptions, RequestOptions} from 'angular2/http';

构建您的自定义选项类,排除BaseRequestOptions

Construct your custom Options class exteding the BaseRequestOptions

class MyCustomOptions extends BaseRequestOptions {
  search: string = 'testingTeam=true';
}

注入它很棘手,你必须在应用程序引导过程中将它们绑定为

Injecting it is tricky, you will have to bind them during your application bootstrap as

bootstrap(App, [HTTP_BINDINGS, bind(RequestOptions).toClass(MyCustomOptions)])
  .catch(err => console.error(err));

在这里,你将它绑定到默认的RequestOptions,这样你就可以说你的角度包含您的自定义选项且有效 ..

Here, you bind it to the default RequestOptions, so that you say your angular to use to include your custom options and they are valid..

此API的详细信息 文件

More Details on this API document.

这篇关于导入后BaseRequestOptions angular2错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆