Angular2 Unable to resolve all parameters for 'RequestOptions' (?)

I tried to import the http provider into one of my own providers. But that throws me the error mentioned above.

At first, I simply imported Http into my ActionTracker-Service. But then I got an error

Exception No provider for AppComponent -> ActionTracker -> Http

So, I also imported Http into my 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]);

action 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){}
}

Upcoming error:

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(…)

When I passed "Http" only in the boots.ts file, I got errors that are missing in ConnectionBackend and RequestOptions. So I added both, but now I'm stuck with an error for RequestOptions.

- , ? ?

!:)

+4
1

RequestOptions RequestOptionsArgs.

, HTTP_PROVIDERS bootstrap:

import {bootstrap} from 'angular2/platform/browser';
import {HTTP_PROVIDERS} from 'angular2/http';

bootstrap(AppComponent, [
  HTTP_PROVIDERS
]);

Angular2 , , HTTP, ,...

, ActionTracker providers . , Angular2. bootstrap.

Angular2, :

, , Thierry

+5

Source: https://habr.com/ru/post/1626303/


All Articles