-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dependency Injection failing when a second decorator is in class #4994
Comments
This sounds like a bug. Thanks for setting up the repro, we will investigate. |
#3583 might be related (and I think it should have fixed it at the time). |
@filipesilva I forgot to mention that you need to install redux-remote dev chrome extension too |
@Jonatthu This seems to be an issue with the https://github.com/zalmoxisus/mobx-remotedev chrome extension. It works perfectly without it as soon as you enable extension it breaks the flow. |
Closing as answered. |
@filipesilva @sumitarora |
@Jonatthu It could be that as they are extending class and then assigning it back which might be affecting the constructor parameters. Still, it would require running the app as well as dev tools running simultaneously both in dev mode to check what is exactly causing this behavior. |
Seems like the issue happens for any extended class. Here's a generic decorator to replicate the issue: function extendClass(target: typeof Store): typeof Store {
return class extends target {
};
} Using it instead of @Injectable()
@extendClass
export class Store {
@observable
public id: number = 1;
constructor(
public _http: Http
) {
console.log(this._http); // it's undefined
}
} Let me know if there's something we can do from our side. |
Thanks @zalmoxisus for investigating |
@sumitarora So this has a possible solution on angular-cli webpack config or it needs another external solution? |
@Jonatthu Will have to investigate what is exactly causing this issue. |
@Jonatthu After investigation current behavior is expected and appropriate. Extending class is decorator is not supported as we do don't support class-level decorators. |
You can also refer to this issue for a similar use case (inheriting from a function call): angular/angular#13436 |
@sumitarora @zalmoxisus Is there another way to make it work with angular knowing this? |
Is there a solution in here? My case is with a Class Decorator. Once I added that to a Component, all dependencies are undefined now. Thanks |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Current behavior
I have a class which I want to inject within it's constructor properties, they are classes too with
@Injection()
decorator,the other classes just have
@Injectable()
decorator and not a second decorator,my index.ts to put the providers in the app module has the right order
and the providers looks like this
and every property on the constructor is undefined. which is weird because on ionic 2 which is using
@angular 2.2.1
is working normally without problems, but a project generated with ng cli is not working which is beta 32, and has angular ^2.4.0, so I'm not sure why this is working in ionic 2 and this not.Expected behavior
Inject each class on the constructor
Minimal reproduction of the problem with instructions
https://github.com/Jonatthu/angular-dependency-injection-failing
What is the motivation / use case for changing the behavior?
Works fine on ionic 2 and this should work as well, without problems.
Angular version: 2.0.X
Angular CLI beta.32.2, ionic has angular 2.2.1 and @angular from angular-cli is 2.4.2
Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
Language: TypeScript
Node (for AoT issues):
node --version
= 6.9.2The text was updated successfully, but these errors were encountered: