Angular Anguar NGRX无法在阵列中插入或删除元素
在我的角度应用程序中,我使用NGRX将元素插入或移除到数组中。 但我总是在分派后得到一个空数组 我现在显示我的代码:Angular Anguar NGRX无法在阵列中插入或删除元素,angular,ngrx,Angular,Ngrx,在我的角度应用程序中,我使用NGRX将元素插入或移除到数组中。 但我总是在分派后得到一个空数组 我现在显示我的代码: export const insertInvalidSearchFields = createAction( 'Insert Invalid Search Fields', props<{invalidSearchField: string}>() ); export const removeInvalidSearchFields = c
export const insertInvalidSearchFields = createAction(
'Insert Invalid Search Fields',
props<{invalidSearchField: string}>()
);
export const removeInvalidSearchFields = createAction(
'Insert Invalid Search Fields',
props<{invalidSearchField: string}>()
);
最后,我要获取字段数组:
this.store.select(getInvalidSearchFields).subscribe((invalidSearchFields: string[]) => {
if(invalidSearchFields.length > 0){
this.buttonDisabled = true;
}else{
this.buttonDisabled = false;
}
})
但我调试发现,无效的搜索字段总是空的
有什么解决方案吗?初始状态是什么样子的?
public setValidationStatus(regExp: string, value: any, field: string): void {
const valid = ValidationHelper.sliderInputValidation(value.toString(), regExp);
if(valid) {
this.store.dispatch(SearchActions.removeInvalidSearchFields({ invalidSearchField: field }))
} else {
this.store.dispatch(SearchActions.insertInvalidSearchFields({ invalidSearchField: field }))
}
this.store.select(getInvalidSearchFields).subscribe((invalidSearchFields: string[]) => {
if(invalidSearchFields.length > 0){
this.buttonDisabled = true;
}else{
this.buttonDisabled = false;
}
})