-
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
Extract class
controller declaration from component declaration
#144
Comments
I like this adjustment too, the only issue with what's written above is re-using the name
This is also tripping up the eslint no-redeclare rule. This issue has been open for awhile, have you had any other positive or negative experience using this pattern in your application? |
I would suggest to extract controller in different file and then import it as You can see an example here |
@ryepup Woops. Made a typo. import templateUrl from './todo-form.html';
class TodoForm {
constructor(EventEmitter) {
'ngInject';
this.EventEmitter = EventEmitter;
}
}
export const TodoFormComponent = {
bindings: {
todo: '<',
onAddTodo: '&'
},
templateUrl,
controller: TodoForm
}; |
good to hear these divergences from the style guide are working out. We're looking to adopt this styleguide at work and trying to figure which bits are the MUSTs and which are the SHOULDs. @aaronte it's not just a typo in this issue, the official docs (e.g. https://github.com/toddmotto/angularjs-styleguide/blame/master/README.md#L331) export const TodoComponent = {
templateUrl,
controller: class TodoComponent {}
} @dima716 that looks pretty good to me, although the guide recommends dropping the name "controller". I think we'll probably try leaving the controller class in the same file as the component like you're suggesting, and pull it into another file if it gets too big. Although controllers aren't supposed to get big, so... |
Hey, currently the
x.component.js
is declared as following where thecontroller
is declared inline with thecomponent
declaration:I was wondering if there's a reason why you chose to do it inline instead of declaring it first before using it like the following:
I think this makes it more readable and lessens indention? Thoughts?
The text was updated successfully, but these errors were encountered: