angular6 - 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)
}
但是得到未定义。我想通过对象将值从子组件传递给父组件并使用两种方式数据绑定我正在关注一些文档但无法正常工作
解决方案
<app-azure-support-enable-auto-shutdown [isEnableAutoshutdown]="isEnableAutoshutdown" (enableAutoshutdown)="enableAutoshutdown($event)" >
推荐阅读
- sql - 基于有效性的 SQL 分组
- bitbucket - 检查您是否有权合并 bitbucket git repo 的多个项目
- java - BouncyCastle 验证抛出 java.lang.IllegalArgumentException:getInstance 中的未知对象:org.bouncycastle.asn1.DERNull
- json - 反应无法访问查询值
- python - 如何使用带有用户定义函数的 Python 进行非线性曲线拟合并找到拟合参数?
- process - 操作系统如何将进程彼此隔离?
- javascript - 为什么窗口调度的事件没有被其他元素捕获?
- python - 模型检查点不创建目录
- indexing - 使用一些索引属性查询数据存储
- python - 有没有办法减少倒置图像中的白色像素