Ben Nadel
On User Experience (UX) Design, JavaScript, ColdFusion, Node.js, Life, and Love.
Ben Nadel at cf.Objective() 2013 (Bloomington, MN) with: Josh Siok
Ben Nadel at cf.Objective() 2013 (Bloomington, MN) with: Josh Siok@siok )

EXCEPTION: No Provider For ParamDecorator In Angular 2 Beta 1

By Ben Nadel on

Since most people are going to be writing Angular 2 using TypeScript, they probably won't run into this error. If you use TypeScript, the combination of Angular 2 decorators and typed constructor arguments will do the work of decorating parameters for you (forgive me if I'm misusing some of the terminology here). But, if you're experimenting with writing Angular 2 in ES5 (like I am), you have to configure the component parameters yourself. And, if you ever forget to "new" your Inject() metadata:

WidgetComponent.parameters = [ ng.core.Inject( ng.core.ElementRef ) ];

... you will get the following error:

EXCEPTION: No provider for ParamDecorator! (Widget -> ParamDecorator)

Here, we are treating Inject() as if it were just a method, when in reality, it's a constructor function. To fix this, all we have to do is add the "new" operator:

WidgetComponent.parameters = [ new ng.core.Inject( ng.core.ElementRef ) ];

As I've been digging into Angular 2 Beta 1, I've tripped over this a number of times, especially when I'm knee-deep in solving a totally different problem. So, I figured I'd make a record of it incase anyone also runs into the error and tries to Google for the error message.




Reader Comments

Post A Comment

You — Get Out Of My Dreams, Get Into My Comments
Live in the Now
Oops!
Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.