Provide and Share Values with Angular 2 Dependency Injection

Share this video with your friends

Send Tweet

TypeScript is used heavily as we build up our application, but TypeScript isn’t required. If you want to Inject a Service without using TypeScript, you’ll need to understand the @Inject decorator. The @Inject decorator also allows you to provide any value or object that you need to share throughout your application without having to create a service.

Owen
Owen
~ 9 years ago

Just a heads up, pretty sure this one should be after the next lesson! ;-)

Ramses
Ramses
~ 9 years ago

Hi, is it ok that I had to use: import {Inject} from 'angular2/di'; instead of (as was told on the video): import {Inject} from 'angular2/angular2';

Zach
Zach
~ 9 years ago

Do you use the colemak keyboard? I noticed you typed "arst" with is the colemak equivalent of asdf.

John Lindquist
John Lindquist(instructor)
~ 9 years ago

Yup, sure do. Nice eye :) I guess it would be pretty hard to roll arst on qwerty.

danielpoulson
danielpoulson
~ 9 years ago

I noticed that you used the public key word, in the Angular docs they use the private. What is the difference between these? I.e Does private refer to the class only and if so does public refer to the application?

Terry DI LUZIO
Terry DI LUZIO
~ 8 years ago

Which dependency injection is the preferred way: @Inject or loading the class in the app.components?

Kevin Pinny
Kevin Pinny
~ 7 years ago

Hello John,

What is the added benefit of injecting the API string via the providers over exporting / importing it?

nortal
nortal
~ 7 years ago

TSLint, that is provided with default settings highlights, that only public class members can be used in template.

Juliana Demarque
Juliana Demarque
~ 7 years ago

Hi, I was reading through Angular StyleGuide and came upon Style 07-04 on the topic of Services. It confused me. Following the videos we are using the @Injectable class decorator, but also using the @Inject parameter to add our services to the constructor. What's really going on with both solutions?