angular-styleguide
angular-styleguide copied to clipboard
ES6 Class
Any intention to use js classes es6 to controllers or services?
I'm looking a way to use these, i.e.
// instead
angular
.module('app')
.controller('LoginController', LoginController);
function LoginController() {
this.credentials;
this.authenticate = authenticate;
function authenticate() {
Authentication.login(this.credentials);
}
}
// es6 implementation
class LoginController() {
constructor(Authentication) {// injection dependency, I guess
this.credentials = {};
}
authenticate() {
Authentication.login()
}
}
angular
.module('app')
.controller('LoginController', LoginController);
It should go by
// es6 implementation
angular
.module('app')
.controller('LoginController', LoginController);
class LoginController() {
constructor(Authentication) {// injection dependency, for sure.
this.credentials = {};
this.Authentication = Authentication;
}
authenticate() {
this.Authentication.login()
}
}
Or something... You can check angular-fullstack generator. I'm not spamming or something, I just used to used it, and they follow pretty good this guide. :).
Yep, I know this generator, is good, unfortunately, they dont follow john papa styleguide.
One thing that bothers me, is the fact of class be generated on scope, only when interpreter read the line, different of functions, they be created in beggining of scope.
But class have better readability of methods and properties, without make ugly things :D, because of that, I'm considering if they be welcome in styleguide
That follow this style guide as best as they willing to. I don't think class should be in any angular style guide, nor that any style guide should be followed strictly. I know I don't follow this strictly.
As you said, classes have better readbility, but Angular was not design arround that, so I think I doesn't make sense to style about it. It's my opinion though.
At the very end, this is just a style guide, the most popular one, yeah, but just a style guide. :).
Respects.
I think you're looking for this fork.