作爲後續於問題:Emit event from Directive to Parent element : Angular2從結構指令角父組件2發射事件不起作用
它看起來時的結構指令發出事件等時,父組件不接收它。
@Directive({ selector: '[appWidget]' })
export class WidgetDirective implements OnInit{
@Output() wdgInit: EventEmitter<any> = new EventEmitter();
@Input() set appWidget (wdg: any) {
//display stuff
}
ngOnInit {
this.wdgInit.emit();
}
widget.component.html:
<ng-container *ngFor="let wdg of widgets">
<div *appTwitterWidget="wdg" >
<ng-container>
widgetContainer.component.html:
<app-widget [widgets]="widgetList" (wdgInit)="containerDoSomthing()"></app-widget>
在這種情況下,我覺得containerDoSomthing()永遠不會獲取調用。