2

Some of examples From angular 2 documents they used for http also

import { HTTP_PROVIDERS }    from '@angular/http';
import { HeroService }       from './hero.service';
@Component({
  selector: 'my-toh',
  template: `
  <hero-list></hero-list>
  `,
  directives: [HeroListComponent],
  providers:  [
    HTTP_PROVIDERS,
    HeroService,
  ]
})
Sarvesh Yadav
  • 2,600
  • 7
  • 23
  • 40

1 Answers1

4

Providers need to be used to provide a way to create instances to inject. For example, if you want to inject an Http instance you need to have define the HTTP_PROVIDERS (that contains the provider for the Http type.

An important thing to understand is that Angular2 supports hierarchical injectors for dependency injector. I mean an injector is associated with each component and the current injector is a child injector of the injector of the parent component.

This question could interest you:

Community
  • 1
  • 1
Thierry Templier
  • 198,364
  • 44
  • 396
  • 360
  • Thanks @Thierry !!! Can You please explain me (source: string, subString: string): boolean; – Sarvesh Yadav May 18 '16 at 11:57
  • You're welcome! It's the TypeScript syntax for methods / functions. A method with two parameters (source of type string and subString of type string) that returns a boolean value. – Thierry Templier May 18 '16 at 12:11