Ben Nadel
On User Experience (UX) Design, JavaScript, ColdFusion, Node.js, Life, and Love.
Ben Nadel at cf.Objective() 2009 (Minneapolis, MN) with: Oguz Demirkapi
Ben Nadel at cf.Objective() 2009 (Minneapolis, MN) with: Oguz Demirkapi@demirkapi )

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.



Looking For A New Job?

100% of job board revenue is donated to Kiva. Loans that change livesFind out more »

Reader Comments