How to create component dynamically with @Output EventEmitter

柔情痞子 提交于 2019-12-11 17:14:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!