export class modifyController implements angular.IComponentController {
static $inject = ['$scope','$state'];
constructor(public $scope:ng.IScope,public $state: ng.ui.IStateService) {
this.sendMessage();
};
public sendMessage(): void {
let tempObj = { 'title': 'name', 'id': '1234' }
this.$scope.$emit('modify',tempObj);
}
}
constructor(public $scope:ng.IScope) {
//need to write this outside constructor
this.$scope.$on('modify', (event: ng.IAngularEvent, data: any) => {
console.log('from ON event...',data);
});
}
在angularjs1.4中,我可以像使用任何其他函数一样直接使用$ scope。$ on(),但是在带有typescript的angularjs1.7中以相同方式使用它时,却出现错误- [ts]意外令牌。构造函数,方法,访问器或属性是预期的。
如何在Typescript,AngularJS1.7中使用this。$ scope。$ on? 谢谢