I am experimenting with the .component() syntax in Angular 1.5.
It seems that the latest fashion is to code the controller in-line in the component rather t
I believe one good approach is to use angular-ts-decorators. With it you can define Components in AngularJS like this:
import { Component, Input, Output } from 'angular-ts-decorators';
@Component({
selector: 'myComponent',
templateUrl: 'my-component.html
})
export class MyComponent {
@Input() todo;
@Output() onAddTodo;
$onChanges(changes) {
if (changes.todo) {
this.todo = {...this.todo};
}
}
onSubmit() {
if (!this.todo.title) return;
this.onAddTodo({
$event: {
todo: this.todo
}
});
}
}
and then register them in your module using:
import { NgModule } from 'angular-ts-decorators';
import { MyComponent } from './my-component';
@NgModule({
declarations: [MyComponent]
})
export class MyModule {}
If you want to check an example of a real application using it, you can check this one.