angular2无法解析’RequestOptions’的所有参数(?)

前端之家收集整理的这篇文章主要介绍了angular2无法解析’RequestOptions’的所有参数(?)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图将http提供程序导入到我自己的提供程序中.但它抛出了上面提到的错误.

首先,我将Http导入我的ActionTracker-Service.但后来我得到了错误

Exception No Provider for 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(…)

当我仅在boots.ts文件中传递’Http’时,我收到ConnectionBackend和RequestOptions缺失的错误.所以我添加了两个,但现在我陷入了RequestOptions的错误.

任何人都可以告诉,为什么会出现这个错误?为什么我还需要将导入的Providers作为数组传递给bootstrap函数

谢谢!

猜你在找的Angularjs相关文章