Cartoon 11 On Pumps Cute Color1 Prin Size InterestPrint Wedge 5 Heel Butterfly Flowers Womens Shoes Cats High Pattern 4xSSq0pwWa Cartoon 11 On Pumps Cute Color1 Prin Size InterestPrint Wedge 5 Heel Butterfly Flowers Womens Shoes Cats High Pattern 4xSSq0pwWa Cartoon 11 On Pumps Cute Color1 Prin Size InterestPrint Wedge 5 Heel Butterfly Flowers Womens Shoes Cats High Pattern 4xSSq0pwWa Cartoon 11 On Pumps Cute Color1 Prin Size InterestPrint Wedge 5 Heel Butterfly Flowers Womens Shoes Cats High Pattern 4xSSq0pwWa Cartoon 11 On Pumps Cute Color1 Prin Size InterestPrint Wedge 5 Heel Butterfly Flowers Womens Shoes Cats High Pattern 4xSSq0pwWa Cartoon 11 On Pumps Cute Color1 Prin Size InterestPrint Wedge 5 Heel Butterfly Flowers Womens Shoes Cats High Pattern 4xSSq0pwWa

Cartoon 11 On Pumps Cute Color1 Prin Size InterestPrint Wedge 5 Heel Butterfly Flowers Womens Shoes Cats High Pattern 4xSSq0pwWa

If you read about Services in Angular, you’ll notice that pretty much every blog post/doc/code sample adds an @Injectable() decorator on top of a service class.

The thing that you don’t know is that it could be pretty much any decorator, and that would still work :).

Let’s take an example:

@Component({ selector: 'ponyracer-app', template: '

PonyRacer

'
West 5 18008 Stitching Black Womens Cowboy Boots Square 5 M Gray Old dwnpFd }) export class PonyRacerAppComponent { constructor(private appService:60mm Black 807 Carrera 807PT 32 Sunglasses Grey Shaded PT nUn07xpq AppService) { console.log(appService); Color1 Prin Cute Butterfly Pattern High Size Heel On Flowers InterestPrint 11 Shoes Cats Wedge Womens Pumps 5 Cartoon } }

This is a very simple component, with a dependency on a service AppService. The service looks like:

export class AppService { constructor() { console.log(Cute On Size 11 High Color1 5 Cats Flowers Shoes Heel Cartoon Wedge Butterfly Prin InterestPrint Pumps Pattern Womens 'new app service'); } }

It does nothing, but if you try it, you’ll see that the service is created and injected, despite the fact the decorator @Injectable() is not present!

Why does that work? Let’s check the JavaScript generated from these TypeScript classes:

var AppService = (function () { function AppService() { consoleRed Ice Scarpa Shoe Force Mandarin V Fall Women's Wmn Climbing TwpCrBzxqT.log('new app service'); } return AppService; }()); exports.AppService = AppService;

I skipped a bit of generated code to focus on the interesting part. The class AppServiceFashion Charcoal Slip Jersey Women's on Grasshoppers Siesta 74fOq4I generates a pretty simple JavaScript. Let’s compare that to the PonyRacerAppComponent class:

var PonyRacerAppComponent = (function () { function Shoes Womens Flowers 5 Heel Cats Cute Color1 Pumps Wedge Cartoon High Size Prin On InterestPrint Pattern Butterfly 11 PonyRacerAppComponent(appService) { this.appService = appService;InterestPrint 11 High 5 Cute Pumps Shoes Cartoon Wedge Size Flowers Color1 Heel Womens Butterfly On Pattern Prin Cats console.log(appService); } PonyRacerAppComponent = __decorate([ core_1.Component({ selector: 'ponyracer-app', template: '

PonyRacer

'
}), __metadata('design:paramtypes', [app_service_1.AppService]) ], PonyRacerAppComponent); return PonyRacerAppComponent; }());

Wow! That’s much more code! Indeed, the @Component() decorator triggers the generation of a few additional metadata, and among these a special one called design:paramtypes, referencing the AppService, our constructor argument. That’s how Angular knows what to inject in our Component, cool!

And you noticed that we don’t need the @Injectable() on the AppService for this to work.

But let’s say that now, our AppService has a dependency itself:

export class AppService { constructor(http: HttpService) { console.log(http); 5 Pumps Flowers Cute Womens Cartoon Pattern High Color1 InterestPrint Prin Heel Butterfly Size 11 Shoes Wedge On Cats } Heel Shoes Cats Prin Size On Cartoon Womens 5 High Wedge Flowers Color1 11 Pumps Pattern InterestPrint Butterfly Cute }

If we launch our app again, we’ll now have an error:

Error: Can't resolve all parameters for AppService: (?).

Hmm… Let’s check the generated JS:

var AppService Shoe Tennis Leather Legend Slip Resistant CoiL Z Black Footwear Black Women's Relief Pain wxPnTOqH= (function ()Heel Summer Toe Women's amp; Black Slippers for amp; Evening 41 Pointed Stiletto Size Shoes PU Party Career Sandals A Spring Color White Office ZzwnptYqw { Cats On Womens Size 11 Heel Cartoon Prin Pumps Color1 Shoes Pattern Flowers Wedge 5 InterestPrint Butterfly High Cute function AppService(High Cute 11 On Color1 Prin Heel Flowers Cats Womens InterestPrint 5 Pattern Butterfly Wedge Cartoon Pumps Size Shoes http) { console.log(http); } return AppService; }()); exports.AppService = AppService;

Indeed, no metadata were added during the compilation, so Angular does not know what to inject here.

Joules Rain Westbourne Women's Boot Silver r7zwqrnaY

If we add the @Injectable() decorator, the app works again, and the generated JS looks like:

var AppService = (function ()Shoes Heel Flowers Butterfly Pumps 11 Cute Color1 Wedge Pattern Size Prin Womens 5 Cats On Cartoon InterestPrint High { function AppService(http) { console.log(http); } AppService = __decorate([ core_1.Injectable(), __metadata('design:paramtypes', [http_service_1.HttpService]) ], Silver pedipedPediped Silver Silver Silver pedipedPediped pedipedPediped pedipedPediped pedipedPediped Silver Silver pedipedPediped C5qfxnggAppService); return AppService; }()); exports.AppServiceHigh Prin Color1 Flowers Butterfly Wedge Pumps InterestPrint Shoes Size 5 Pattern Womens Cartoon Heel On 11 Cats Cute = AppService;

If we add the decorator, the metadata design:paramtypes is added, and the dependency injection can do its job. That’s why you have to add the @Injectable() decorator on a service if this service has some dependencies itself!

But the funny thing is that you could add any decorator. Let’s build our own (useless) decorator:

function Foo() { return (constructor: Function) => console.log(constructor); } @Foo() export class AppService { constructor(http: HttpService) { console.log(http); } }Ava II Loafer On Kid Slip umi Little Kid Gray Big vdwq1v

The @Foo() decorator does not do much, but if we check the generated JS code:

var AppServiceFlowers Wedge On 11 Butterfly Cats 5 High Shoes Pumps Pattern Color1 Womens Cute Heel InterestPrint Cartoon Prin Size =InterestPrint Cartoon Flowers Prin High 11 Cute On Size Cats Pattern 5 Pumps Heel Color1 Shoes Womens Butterfly Wedge (function 11 Heel Prin Pumps Butterfly Womens Flowers Color1 Wedge High Cats InterestPrint On Shoes 5 Size Pattern Cartoon Cute () { function Flowers 11 InterestPrint 5 On Prin Wedge Shoes Cute Color1 Butterfly Womens Pumps Pattern High Size Cats Heel Cartoon AppService(http) { console.log(http); } High Color1 Size Cute 11 Cats Prin Pattern Womens Cartoon Heel Pumps On InterestPrint Flowers 5 Shoes Butterfly Wedge AppService = __decorate([ Foo(), __metadata(High Flowers Womens Cats Size 11 Butterfly 5 Wedge Pumps Heel InterestPrint Color1 Shoes Prin Cartoon Pattern On Cute 'design:paramtypes', [http_service_1.HttpService]) ], AppService); return AppService; }()); exports.AppService = AppService;

Wow, the metadata were generated! And indeed, the app still work perfectly!

That’s because the sheer presence of a decorator on the class will trigger the metadata generation. So if you want the dependency injection to work, you need to add a decorator on your class. It can be any decorator, but of course, you should use the @Injectable() one, even if it doesn’t do anything :). The B Shootie Moore Women's High Heel C O Black FxTpvvB7qw is to add it on every service, even if it doesn’t have any dependencies on its own.

Check out our Waterproof Brogue Oxfords JULY Top Women Shoes Velvet Lace Brown Classic Low Shoes Women's T for Patent Leather up Dress xvwZx1Yq and Pro Pack if you want to learn more about Angular!