-
Notifications
You must be signed in to change notification settings - Fork 699
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
Component Controller - Inject new service require change in 3 place #85
Comments
@phucpnt First thing you can do is to remove the assignment of your Service to a variable in constructor. If you declare your Service parameter as |
@d3lm thanks for your comments. I'm still thinking about how to make the connection between the different services more easily to grasp by. I has a few idea regards the dependency injection but those not connected well and give me clearer picture till now... I will keep you posted. |
@phucpnt I wrote a small function which automatically bind the injected dependencies to Check out the class wrapper: function binder(constructor) {
function wrapConstructor () {
var args = Array.prototype.slice.call(arguments);
constructor.$inject.reduce((self, depName, depIndex) => {
self[depName] = args[depIndex];
return self;
}, this);
return constructor.apply(this, args);
}
wrapConstructor.prototype = constructor.prototype;
wrapConstructor.$inject = constructor.$inject;
return wrapConstructor;
}
// Usage:
// module.exports = binder(YourController); Note: I didn't test it with angular. I adapted the instantiation of angular for testing. |
@floriangosse Looks good, as long as you don't minify your code. But I guess ngAnnote can solve that. |
@d3lm how exactly? Typescript? |
@AkosLukacs Sure, if you minify your code without ngAnnotate it will break but application. But you should use strictDi and ngAnnotate. |
@caioiglesias Yes, I was refering to TypeScript. The constructor would look like this:
Then FooService is then available by accessing |
Hello,
Whenever you inject a new service, you need to change 3 place: 1) register the server 2) add new params into the constructor 3) assign the service into the component
this
. Please check the image I attach. Should we simplify those requirements?The text was updated successfully, but these errors were encountered: