作为后续于问题: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()永远不会获取调用。