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
If you wanted to completely adopt an Angular 2 approach, you could use:
module.ts
import { MyComponent } from './MyComponent';
angular.module('myModule', [])
.component('myComponent', MyComponent);
MyComponent.ts
import { Component } from './decorators';
@Component({
bindings: {
prop: '<'
},
template: '{{$ctrl.prop}}
'
})
export class MyComponent {
prop: string;
constructor(private $q: ng.IQService) {}
$onInit() {
// do something with this.prop or this.$q upon initialization
}
}
decorators.ts
///
export const Component = (options: ng.IComponentOptions) => {
return controller => angular.extend(options, { controller });
};