基于表达的角结合形式结合形式
我的请求数据中有2个数组。一种包含包括产品,另一个包含产品。您不能同时使用这两者。因此,我有这样的html:
<input [formControl]="this.exclude$ ? excludedFormControl : includedFormControl>
<mat-slide-toggle (change)="excludeChange($event.checked)"></mat-slide-toggle>
这是我的TS:
exclude$ = new BehaviorSubject<boolean>(false);
currentFilter = {
productsSection: {
includedIds: [],
excludedIds: [],
},
};
includedFormControl: FormControl = new FormControl(
this.currentFilter.productsSection.includedIds ? this.currentFilter.productsSection.includedIds : [],
);
excludedFormControl : FormControl = new FormControl(
this.currentFilter.productsSection.excludedIds? this.currentFilter.productsSection.excludedIds: [],
);
excludeChange(value: boolean): void {
this.filterForm.patchValue({
includedIds: [],
excludedIds: [],
});
this.exclude$.next(value);
}
showFormValue() {
console.log(this.filterForm.value);
}
问题:当我滑动切换时,dubludechange被调用,但是输入仍然将数据写入纳入incruffeids中,忽略了滑块。
I have 2 arrays in my request data. One contains included products, other - excluded. You can't use both at the same time. So i have such HTML:
<input [formControl]="this.exclude$ ? excludedFormControl : includedFormControl>
<mat-slide-toggle (change)="excludeChange($event.checked)"></mat-slide-toggle>
Here is my TS:
exclude$ = new BehaviorSubject<boolean>(false);
currentFilter = {
productsSection: {
includedIds: [],
excludedIds: [],
},
};
includedFormControl: FormControl = new FormControl(
this.currentFilter.productsSection.includedIds ? this.currentFilter.productsSection.includedIds : [],
);
excludedFormControl : FormControl = new FormControl(
this.currentFilter.productsSection.excludedIds? this.currentFilter.productsSection.excludedIds: [],
);
excludeChange(value: boolean): void {
this.filterForm.patchValue({
includedIds: [],
excludedIds: [],
});
this.exclude$.next(value);
}
showFormValue() {
console.log(this.filterForm.value);
}
Problem: When i slide the toggle the excludeChange gets called, but the input still writed the data into the includedIds, ignoring the slider.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您必须从
排除$
订阅。在component.ts文件中,您必须定义
排除
。I think you have to subscribe from the
exclude$
.In component.ts file, you have to define
excluded
.