【发布时间】:2021-03-28 03:05:18
【问题描述】:
我有一个问题,我的 Angular 应用程序中的 @input 值无法更新
我的代码 在子组件中
@Input() canAddMore?: boolean;
public setButtonVisible(){
this.canAddMore = false;
}
子组件html
<button mat-mini-fab color="primary"
(click)="setButtonVisible()" *ngIf="canAddMore">
<mat-icon>add</mat-icon>
</button>
如果在表单中添加了输入字段,将调用此函数
在父组件中
<app-field
[canAddMore]="canAddMore"
>
</app-field>
在父组件中也有一个按钮
public canAddMore: boolean;
public setButtonVisible(){
this.canAddMore = true;
}
父组件中有一个按钮,改变canAddMore = true。
问题是,如果我在子组件中调用setButtonVisible,然后在父组件中调用setButtonVisible,
canAddMore 不会更新。
有什么解决办法吗?
【问题讨论】:
-
请查看这是否可以帮助stackoverflow.com/questions/64333325/…
标签: angular