使用 2 路绑定访问 Angular 6 组件库值 [英] Access Angular 6 component library values with 2 way binding

查看:24
本文介绍了使用 2 路绑定访问 Angular 6 组件库值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Angular 6我已经成功创建了一个 Angular 组件库并添加了一个包含下拉控件的组件.

Working in Angular 6 I've successfully created a Angular Component Library and added a component that has a drop down control in it.

我已经在 app.module 中添加了必要的导入并显示了我的库组件!!!

I've added the neccessary imports in app.module and got my library component to show up!!!

..使用它的选择器

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

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

The problem I'm having is how do I get the value that is selected from the dropDown in the 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>

这篇关于使用 2 路绑定访问 Angular 6 组件库值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆