首页 > 解决方案 > Angular8在子组件中传递@input类对象然后在父组件中访问这个值不起作用

问题描述

Below are child component code :

 @Input('enableAutoshutdown') enableAutoshutdown: EnableAutoshutdownObject;
    @Output() data = new EventEmitter<EnableAutoshutdownObject>();
    
    sendData() {
      let enableAutoshutdownObject = new EnableAutoshutdownObject();
      enableAutoshutdownObject.ShutdownTime = this.fgEnbleAutoShutdownVm.value.ShutdownTime;
      this.enableAutoshutdown = enableAutoshutdownObject;
      this.data.emit(this.enableAutoshutdown);
    }
    below are parent component code:
    <app-azure-support-enable-auto-shutdown [isEnableAutoshutdown]="isEnableAutoshutdown" [(enableAutoshutdown)]="enableAutoshutdown" ></app-azure-support-enable-auto-shutdown>
    
    .ts
    ngOnInit(): void {
    console.log(this.enableAutoshutdown)
    }

但是得到未定义。我想通过对象将值从子组件传递给父组件并使用两种方式数据绑定我正在关注一些文档但无法正常工作

标签: angular6angular8

解决方案


<app-azure-support-enable-auto-shutdown [isEnableAutoshutdown]="isEnableAutoshutdown" (enableAutoshutdown)="enableAutoshutdown($event)" >


推荐阅读