Я попытался импортировать поставщика http в один из моих собственных поставщиков. Но это бросает мне ошибку, упомянутую выше.angular2 Не удается разрешить все параметры для 'RequestOptions' (?)
Сначала я просто импортировал Http в свою службу ActionTracker-Service. Но потом я получил ошибку
Исключение Нет Provider для AppComponent -> ActionTracker -> Http
Так я и импортировала 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(…)
Когда я передал «Http» только в файле boots.ts, у меня появились ошибки, которые отсутствуют в ConnectionBackend и RequestOptions. Поэтому я добавил оба, но теперь я застрял с ошибкой для RequestOptions.
Может кто-нибудь сказать, почему эта ошибка появляется? И зачем мне также передавать мои импортированные Провайдеры в функцию бутстрапа как массив?
Спасибо! :)
Вы не должны включая ConnectionBackend, RequestOptions, Http при загрузке, вместо этого используйте HTTP_PROVIDERS https://angular.io/docs/ts/latest/api/http/HTTP_PROVIDERS-let.html , с другой стороны, вы должны добавить ActionTracker в bootstrap – kit