1

See for example this line:

constructor(private elementRef: ElementRef, private zone: NgZone) {}

I need to remove the parmas from the constructor in order for the downgrade to work with no error. Else I get

(SystemJS) Can't resolve all parameters for (?)

So I found a way to remove element ref with:

@ViewChild('myname') divElementRef:ElementRef;

But I don't find any solution how to declare the NgZone, I always get it is undefined and I can do "run" with it. If someone know how I can create instance of ngZone outside the constructor it will help, or may explain the error I get while downgrade componenet.

Are the constructor params should be part ot the input I declare while downgrade a component?

angular.module('myModule').directive('myLabel', downgradeComponent({component: MyLabelComponent, inputs: ['text'] }) as angular.IDirectiveFactory)

if the constructor of MyLableComponent look like this:

constructor(private elementRef: ElementRef) {}

I will get the error message. Hope someone can explain why. While removing the constructor parmas everything will work fine.

AngularOne
  • 2,760
  • 6
  • 32
  • 46
  • 1
    Have you tried with `@Inject(NgZone) private zone: NgZone` and the same for `ElementRef`? – dlcardozo Feb 21 '17 at 17:18
  • OMG! you just saved me about half a day of wondering why it doesn't work. Thank you so MUCH!!!!! – AngularOne Feb 21 '17 at 17:22
  • I will be happy to understand why the @inject is neccary here, since if I don't downgrade it will work fine – AngularOne Feb 21 '17 at 17:23
  • this seems to be an issue with the injector, but I have never tried to use a component in a downgrade like that one, I don't know if you have a way to declare the providers in angular 1, or maybe just adding the $inject = [NgModule] will work, don't know. – dlcardozo Feb 21 '17 at 17:32

1 Answers1

3

DI has to be provided by the module, it will be inherited by lower modules.

I have never tried to use a downgrade like that one, but seems to be an issue with the way to provide the classes to inject, maybe the mechanism for that doesn't exists when you are running the component on this way.

Try with @Inject(NgZone) private zone: NgZone and @Inject(ElementRef) elementRef: ElementRef

Happy coding!

dlcardozo
  • 3,953
  • 1
  • 18
  • 22