Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

import HTTP_PROVIDERS in app.component.ts

Tags:

angular

When I try to import the HTTP_PROVIDERS from angular/http I have this error:

Error:(3, 9) TS2305: Module '"projectname/node_modules/@angular/http/index"' has no exported member 'HTTP_PROVIDERS'.

this is my file content:

import { Component } from '@angular/core';
import {GithubService} from './services/github.service';
import {HTTP_PROVIDERS} from  '@angular/http';

@Component({
    selector: 'my-app',
    template: '<h1>My First Angular 2 App</h1><Profile></Profile>',
    providers: [ HTTP_PROVIDERS, GithubService ]
})

export class AppComponent { }
like image 336
Mohamed Ben HEnda Avatar asked Sep 07 '16 15:09

Mohamed Ben HEnda


2 Answers

If you use >= RC.5 add HttpModule to imports in @NgModule instead:

@NgModule({
  imports: [HttpModule],
  ...
})
class AppModule {}
like image 114
Günter Zöchbauer Avatar answered Oct 20 '22 04:10

Günter Zöchbauer


What if i want to write an auth-interceptor using e.g.

import { provideAuth } from 'angular2-jwt';
...
bootstrap(App, [
  HTTP_PROVIDERS,
  provideAuth({
    headerName: YOUR_HEADER_NAME,
    headerPrefix: YOUR_HEADER_PREFIX,
    tokenName: YOUR_TOKEN_NAME,
    tokenGetter: YOUR_TOKEN_GETTER_FUNCTION,
    globalHeaders: [{'Content-Type':'application/json'}],
    noJwtError: true,
    noTokenScheme: true
  })
])

First, there is no HTTP_PROVIDERS in @angular/http. Second, there is no bootstrap in @angular/platform-browser-dynamic

Everywhere you find simillar thing s when you want to write your auth interceptor, but nowhere it is written how to do it whith the released version of angular 2 :( All examples are just not working anymore :( Can anyone tell me how to write an auth interceptor with hte RELEASED version of angular2, i.e. @angular/*:2.0.0

like image 2
choosyg Avatar answered Oct 20 '22 03:10

choosyg