传递数据 - 从子级到父级Angular 6的对象

问题描述 投票:-1回答:1

在子组件中,我有一个数据表,当我点击该行时,我将获取数据并将其保存在branchToDivision中,我还有一个按钮,当我点击该按钮时,我可以将branchToDivision发送到父组件。

儿童组件

@Output() messageEvent: EventEmitter<BranchDto> = new EventEmitter<BranchDto>();
branchToDivision: BranchDto;
onSelect(record: BranchDto) {
        this.branchToDivision = new BranchDto();
        this.branchToDivision = record;
        console.log(this.branchToDivision);
        console.log(this.branchToDivision.brancH_CODE);
    }
acceptBranch() {
        this.onSelect(this.branchToDivision);
        this.messageEvent.emit(this.branchToDivision);
        this.branchModalDivision.hide();        
    }

父组件

branch: BranchDto;
getBranch(branch: BranchDto): void{
        this.branch = branch;
        console.log(this.branch);
        console.log(this.branch.brancH_CODE);       
    }

父HTML

<branchModal #branchModal (messageEvent)="getBranch($event)" ></branchModal>

我尝试记录分支属性,但它是未定义的,有什么问题?任何想法都对我很有帮助。

parameter-passing angular6 eventemitter
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.