0

在 Angular 6 中工作我已经成功创建了一个 Angular 组件库并添加了一个包含下拉控件的组件。

我在 app.module 中添加了必要的导入,并让我的库组件显示出来!!!

..使用它的选择器

<my-custom-dropdown></my-custom-dropdown> 

我遇到的问题是如何获取从 app.component 的下拉菜单中选择的值?

任何帮助是极大的赞赏!!

4

1 回答 1

1

父组件模板:

<my-custom-dropdown (selectedValue)="handleselectedvalue($event)"></my-custom-dropdown>
<!-- Add a handleselectedvalue($event) function in your parent component. $event will contain the selected value -->

在您的子组件中:

@Output() selectedValue = new EventEmitter</*type of selected value goes here*/>();

handleSelection(event) {
    this.selectedValue.emit(event);
}

子组件模板:

<!-- Child component template -->
<someElement (click)="handleSelection($event)"></someElement>
于 2018-09-20T20:13:44.133 回答