问题
There are 2 uses for the my-select component:
the use-my-select.html template
created dynamically.
It works in the template but not when created dynamically.
How do I create the my-select component dynamically so that mySelected() is called?
my-select.ts
@Component({
selector: 'my-select',
templateUrl: './my-select.html'
})
export class MYSelect {
@Output() mySelected: EventEmitter<string> = new EventEmitter();
}
use-my-select.html
<my-select (mySelected)="mySelected($event)" ></my-select>
use-my-selct.ts
@ViewChild('select') select: MYSelect;
Object.assign(this.select, { mySelected: "mySelected()" });
mySelected(option) {
}
来源:https://stackoverflow.com/questions/54932287/how-to-create-component-dynamically-with-output-eventemitter