You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Providing from inheritor to constructor of base component doesn't work in Angular 4 #15615
[X] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
After updating to Angular 4 code below throws errors (Cannot read property 'instance' of undefined). It was working without any problems before update:
same here. On Angular 2.4.x it was possible to inject all providers inside the constructor, since 4.0.x its not possible.
Here one example: http://plnkr.co/edit/byWUOe?p=preview
VM6686 App_Host.ngfactory.js:5 ERROR ReferenceError: injector is not defined
at App.Base.ngOnInit (VM6533 app.ts!transpiled:39)
at App.ngOnInit (VM6533 app.ts!transpiled:52)
Activity
DzmitryShylovich commentedon Mar 30, 2017
Doesn't work even without inheritance http://plnkr.co/edit/h4WlNJ6jwOVlCjVYXAIL?p=preview
DzmitryShylovich commentedon Mar 30, 2017
cc @tbosch
moohkooh commentedon Apr 4, 2017
same here. On Angular 2.4.x it was possible to inject all providers inside the constructor, since 4.0.x its not possible.
Here one example:
http://plnkr.co/edit/byWUOe?p=preview
tbosch commentedon Apr 10, 2017
Note: This is a general bug when using
Injectorand eager providers (useValueis always eager)CSchulz commentedon Apr 20, 2017
Doesn't work either with
useClass. I have encountered this issue on upgrade to Angular 4.CindySLiu commentedon Jun 4, 2017
I have some issue. Do we have any work around so that we can use Angular 4?
shelacek commentedon Jun 13, 2017
We use something like this as workaround:
ivanpadavan commentedon Jun 13, 2017
There is one another workaround:
CindySLiu commentedon Jul 10, 2017
@ivanpadavan Does your work around work for regular Angular class instead of Angular component?
Will ngOnInit() be called in Angular class who implements OnInit?
CindySLiu commentedon Jul 10, 2017
@ivanpadavan I tried your work around. It doesn't work. this.injector in BaseComponent is undefined when its ngOnInit is called.
CindySLiu commentedon Jul 10, 2017
@ivanpadavan I used your work around to fix the issue in http://plnkr.co/edit/5yeUn0j1VxASsAD0657n?p=preview
(to brake it uncomment 26 line of app.ts). I got the following error:
VM6686 App_Host.ngfactory.js:5 ERROR ReferenceError: injector is not defined
at App.Base.ngOnInit (VM6533 app.ts!transpiled:39)
at App.ngOnInit (VM6533 app.ts!transpiled:52)
huntering commentedon Jul 12, 2017
@CindySLiu in stead of
useValue: 'Nice to meet you'use this
useFactory: () => 'Nice to meet you!'trotyl commentedon Feb 13, 2018
Duplicate of #15501, already fixed by #19558 in
4.4.5.wbhob commentedon Jul 6, 2018
It looks to me like this issue can be closed, since it has been fixed. Can you close it please @ivanpadavan
andzejsw commentedon Aug 22, 2019
I am using different approach.
From app.module.ts constructor i am calling service setter, which one needs to include that other service.
Bur in WampService setErrorHandlermethod looks like this:
angular-automatic-lock-bot commentedon Sep 22, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.