我正在尝试将值从 Angular2 中的一个组件传递到另一个组件。例如,我正在尝试实现一个组件并在该组件中设置数据和标题,然后将该数据和标题传递给嵌入其中的另一个组件?
这是更好解释的代码。
<cst-multiselect [title]="Countries" [data] = ['one', 'two', three']></cst-multiselect>
我正在努力传递价值观'title' and 'data' 到另一个组件:
<div ngbDropdown class="d-inline-block" [autoClose]="false">
<button class="btn btn-outline-primary" id="dropdownMenu1" ngbDropdownToggle>Selected Countries
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenu1">
<cst-checkbox></cst-checkbox>
</div>
</div>
我想在 cst-checkbox(这是一个下拉框)上显示从 cst-multiselect 传递的数据。我想设置该下拉框中的值和数据。任何帮助将不胜感激,因为我一直在尝试多种方法但无济于事。谢谢你!
@Component({
selector: 'cst-multiselect',
template: '<cst-checkbox [title]="title" [data]="data"'
...
})
class CstMultiSelect {
@Input() title:string;
@Input() data:string[];
}
@Component({
selector: 'cst-checkbox',
...
})
class CstCheckbox {
@Input() title:string;
@Input() data:string[];
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)