[英]Angular change the value after EventEmitter
I have a component that is a sort of toggle functionality. 我有一个具有某种切换功能的组件。
<label *ngIf="value" (click)="toogleLuckBet()">On</label>
<label *ngIf="!value" (click)="toogleLuckBet()">Off</label>
export class GameStarComponent {
@Input() value: boolean;
@Input() disabled: boolean;
@Output() valueChange = new EventEmitter<boolean>();
constructor() {
this.value = false;
this.disabled = false;
}
toogleLuckBet() {
this.value = !this.value;
this.valueChange.emit(this.value);
}
}
This component is being used inside a foreach and what I would like to do is based on certain conditions of other fields allow the value to change or not. 这个组件正在foreach内部使用,我想做的是基于其他字段的某些条件允许值更改或不更改。 So my idea was to have a valueChanged when calling that component
所以我的想法是在调用该组件时要有一个valueChanged
<game-star [(value)]="game.isLuckBet" (valueChange)="changeLuckBet()"></game-star>
And on the parent component, implement the function changeLuckBet that would check the scenario and if necessary change the value of the game.isLuckBet property back to false. 并在父组件上实现函数changeLuckBet,该函数将检查场景,并在必要时将game.isLuckBet属性的值更改为false。
What happens is that even that I see the property changed while debugging, after everything the property is in the true state, as if I never changed it on the parent component. 发生的事情是,即使我看到调试时该属性发生了更改,但在所有属性都处于真实状态之后,好像我从未在父组件上进行更改一样。
What am I missing? 我想念什么?
Can u try using property binding instead of two way binding by changing 您是否可以尝试通过更改来使用属性绑定而不是双向绑定
[(value)]="game.isLuckBet"
To
[value]="game.isLuckBet"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.