服务
export class RandomServiceName implements ng.IServiceProvider {
/* @ngInject */
constructor(private $rootScope: ng.IRootScopeService) {
}
public $get(): RandomServiceName {
return this;
}
doStuff() {
this.$rootScope.$broadcast('hello', 'world');
}
}
控制器
import {RandomServiceName} from './random_service_name.ts';
export class RandomController {
/* @ngInject */
constructor(private $rootScope: ng.IRootScopeService,
private $log: ng.ILogService,
private RandomServiceName: RandomServiceName) {
this.RandomServiceName.doStuff();
this.$rootScope.$on('hello', (event: ng.IAngularEvent, data: string) =>
this.$log.info(`Event '${event.name}' caught with data ${data}`)
);
}
}
但这没有意义,因为constructor
仅调用一次(每次启动)...:\