使用 2 种方式绑定访问 Angular 6 个组件库值
Access Angular 6 component library values with 2 way binding
工作时间 Angular 6
我已经成功创建了一个 Angular 组件库并添加了一个具有下拉控件的组件。
我已经在 app.module 中添加了必要的导入,并显示了我的库组件!!!
..使用其选择器
<my-custom-dropdown></my-custom-dropdown>
我遇到的问题是如何获取从 app.component 中的下拉菜单中选择的值?
非常感谢任何帮助!!
父组件模板:
<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>
工作时间 Angular 6 我已经成功创建了一个 Angular 组件库并添加了一个具有下拉控件的组件。
我已经在 app.module 中添加了必要的导入,并显示了我的库组件!!!
..使用其选择器
<my-custom-dropdown></my-custom-dropdown>
我遇到的问题是如何获取从 app.component 中的下拉菜单中选择的值?
非常感谢任何帮助!!
父组件模板:
<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>