在ngOnInit组件的方法中,@ Invput值将被绑定,因此您可以检查组件上的这些属性,但似乎没有办法检查@Output事件绑定.我希望能够知道@Output是否已连接到组件上.
(使用Angular 2 beta 2和TypeScript)
import {Component, Output, EventEmitter} from 'angular2/core';
@Component({
selector: 'sample',
template: `<p>a sample</p>`
})
export class SampleComponent {
@Output() cancel = new EventEmitter();
ngOnInit() {
// would like to check and see if cancel was used
// on the element <sample (cancel)="doSomething()"></sample>
// or not <sample></sample>
}
}
Run Code Online (Sandbox Code Playgroud)