简体   繁体   English

如何在Angular2中将值从一个组件传递到另一个组件?

[英]How to pass value from one component to another component in Angular2?

I am trying to pass a value from one component to another in Angular2. 我试图在Angular2中将值从一个组件传递到另一个。 So for example, I am trying to implement a component and set a data and title in that component and pass that data and title to another component which is embedded in it? 因此,例如,我正在尝试实现一个组件,并在该组件中设置数据和标题,然后将该数据和标题传递给嵌入其中的另一个组件?

Here is the code to better explain. 这是更好解释的代码。

<cst-multiselect [title]="Countries" [data] = ['one', 'two', three']></cst-multiselect>

I am trying to pass the values ' title ' and ' data ' to another component: 我正在尝试将值“ title ”和“ 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>

I would like to display the data I passed from cst-multiselect on cst-checkbox(which is a dropdownbox). 我想在cst-checkbox(这是一个dropdownbox)上显示从cst-multiselect传递的数据。 I would like to set the value and also the data in this dropdownbox. 我想在此下拉框中设置值以及数据。 Any help would really be appreciated as I have been trying out multiple methods but to no avail. 真的很感激任何帮助,因为我一直在尝试多种方法,但无济于事。 Thank you! 谢谢!

@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[];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Angular2中将变量值从一个组件传递到另一个组件 - How to pass variable value from one component to another in Angular2 如何在angular2中将数组的索引从一个组件传递到另一个组件? - How to pass index of an array from one component to another in angular2? 如何将数据从一个组件传递到另一个 angular2 - How to Pass the data from one component to another angular2 将数值从一个组件发送到Angular2中的另一个组件 - Send a number value from one component to another component in Angular2 如何将数据从一个子组件传递到angular2中的另一个子组件? - How to pass data from one child component to another child component in angular2? 如何从另一个组件调用一个组件中的方法是 angular2 - how to call a method in one component from another component is angular2 将参数从一个组件传递到另一个angular2 - pass params from one component to another angular2 Angular2:如何通过表单将值传递给另一个组件 - Angular2 : How to pass value through a form to another component 如何以角2将变量值从一个组件传递到另一组件 - How to pass variable value from one component to another in angular 2 如何将值从一个组件传递到另一个组件? (有角度的) - How to pass value from one component to another? (Angular)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM