-
Notifications
You must be signed in to change notification settings - Fork 135
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
no-constructor-vars breaks DI #106
Comments
You need to set the class's instance of auth to the one passed in the constructor: export class MyClass {
private auth: Authentication;
constructor(auth: Authentication) {
this.auth = auth;
} Please reopen if this doesn't work. |
That works. Thank you for the quick reply. I'm left with this question: Which is better--not manually assigning constructor parameters or not declaring parameters in the constructor? |
Based on the way Ionic 2 generates classes, I think they've answered that question a certain way. |
IMO explicit is better than implicit. When you implicitly declare in the constructor it isn't clear that those variables are being assigned to the class ( It's all very subjective, but I think clearer is better. |
I copied the
tslint.json
from this repository and updated my code to conform to the rules. That seemed to break my app. If I declare a provider in the ionicBootraps function:but then declare its visibility like so:
MyClass's auth is
undefined
. Whereas if I do this instead:It Just Works™.
The text was updated successfully, but these errors were encountered: