angular2无法解析’RequestOptions’的所有参数(?)
发布时间:2020-12-17 17:25:48 所属栏目:安全 来源:网络整理
导读:我试图将http提供程序导入到我自己的提供程序中.但它抛出了上面提到的错误. 首先,我将Http导入我的ActionTracker-Service.但后来我得到了错误 Exception No Provider for AppComponent - ActionTracker - Http 所以我也把Http导入了我的boot.ts. 的index.htm
|
我试图将http提供程序导入到我自己的提供程序中.但它抛出了上面提到的错误.
首先,我将Http导入我的ActionTracker-Service.但后来我得到了错误
所以我也把Http导入了我的boot.ts. 的index.html <html>
<head>
<title>Angular 2 QuickStart</title>
<!-- 1. Load libraries -->
<script src="angular2/bundles/angular2-polyfills.js"></script>
<script src="systemjs/dist/system.src.js"></script>
<script src="rxjs/bundles/Rx.js"></script>
<script src="angular2/bundles/angular2.dev.js"></script>
<script src="angular2/bundles/http.dev.js"></script>
<!-- 2. Configure SystemJS -->
<script>
System.config({
packages: {
app: {
format: 'register',defaultExtension: 'js'
}
}
});
System.import('app/boot')
.then(null,console.error.bind(console));
</script>
<link href="bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="font-awesome/css/font-awesome.min.css" rel="stylesheet">
<link href="assets/styles/main.css" rel="stylesheet">
</head>
<!-- 3. Display the application -->
<body>
<my-app>Loading...</my-app>
</body>
</html>
boot.ts import {bootstrap} from 'angular2/platform/browser'
import {AppComponent} from './app.component'
import {Http,ConnectionBackend,RequestOptions} from 'angular2/http'
bootstrap(AppComponent,[ConnectionBackend,RequestOptions,Http]);
行动tracker.service.ts import {Injectable} from 'angular2/core';
import {Track} from './track'
import {Http} from 'angular2/http'
@Injectable()
export class ActionTracker {
constructor(private _http:Http){}
}
即将发生的错误是: Cannot resolve all parameters for 'RequestOptions'(?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'RequestOptions' is decorated with Injectable. Error: Cannot read property 'getOptional' of undefined(…) 当我仅在boots.ts文件中传递’Http’时,我收到ConnectionBackend和RequestOptions缺失的错误.所以我添加了两个,但现在我陷入了RequestOptions的错误. 任何人都可以告诉,为什么会出现这个错误?为什么我还需要将导入的Providers作为数组传递给bootstrap函数? 谢谢! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
