我一直在尝试在Angular中将数据从子组件发送到父组件。在父级,道具不断返回“undefined”我不知道我错过了什么。
儿童内容
@Output() onGetDropdownItems: EventEmitter<any> = new EventEmitter<any>(); getDropdownItems() { this.onGetDropdownItems.emit(this.dropdownItems) } /** * Sets the data for the Items per page select dropdown. */ @Input() dropdownItems: [ { optionValue: "5", optionText: "5", }, { optionValue: "10", optionText: "10", }, { optionValue: "20", optionText: "20", } ]
PARENT.com组件
@Input() dropdownItems: any; getDropdownItems(e: any) { this.dropdownItems = e; console.log('DROPDOWN ITEMS: ', e); } ngOnInit() { this.getDropdownItems(this.dropdownItems); }
PARENT.com组件.html
<cbds-pagination (onGetDropdownItems)="getDropdownItems($event)"> </cbds-pagination>
这个 dropdownItems 属性的值被定义为类型。
dropdownItems
@Input() dropdownItems: any = [ { optionValue: "5", optionText: "5", }, { optionValue: "10", optionText: "10", }, { optionValue: "20", optionText: "20", } ]