例如,我想每 10 秒更新一次列表。我使用了运算符“timer”,但 api 没有在 Chrome -> Network 选项卡上第二次显示。
我的流程:调度加载操作 - 我的 api - 方法 GET - 仅在“网络”选项卡中调用一次。但是,如果我创建了一个带有函数调度该操作的按钮,则每次我单击时,我的 api 都会在“网络”选项卡/Chrome 中被调用多次
我的环境:ngrx 7.4、rxjs 6.5.2、Angular 7 所以我不知道服务器自动阻止重复调用 api 或 Angular 和 ngrx 是否正在使用缓存
// 我的效果
load$: Observable<Action> = this.action$.pipe(
ofType<Load>(NotificationActionTypes.load),
switchMap(() => timer(0, 10000)),
switchMap((action) => {
return this.notiService.getNotifications().pipe(map((res: any) => {
return new LoadSuccess({
result: res,
});
}));
})
);```
[![enter image description here][1]][1]
See my image, 20/125 request, 125 continue increasing, 20/130, 20/145, but number 20 didn't increase
[1]: …Run Code Online (Sandbox Code Playgroud) 我的应用程序中有不同的选择器,但由于某种原因,当我的商店发生更改时,这个特定的选择器不会更新,我不知道为什么。行的代码selectDataStream在第一次之后永远不会运行,随后的存储更改并且没有任何反应。我看到我的新值已在商店中更新。
成分:
ngAfterViewInit(): void {
if (this.fields && this.fields.length > 0) {
this.store$.select<any[]>(getConnections(this.connectorId))
.takeUntil(this.onDestroy$).subscribe(connections => {
this.selectDataStream.next(connections);
this.cdRef.detectChanges();
});
}
}
Run Code Online (Sandbox Code Playgroud)
减速器代码:
const model = state.connectionresults[connectionId];
const updatedstate = {
...state,
connectionresults: {
...state.connectionresults,
[connectionId]: {
...model,
connections: [...payload]
}
}
};
return {
...updatedstate
};
Run Code Online (Sandbox Code Playgroud)
选择器:
export const selectConnectionResults = createSelector(
selectFinderData,
(state: FinderState) => state.connectionresults
);
export const getConnections = (id) => createSelector(selectConnectionResults, entities => {
return entities[id];
});
Run Code Online (Sandbox Code Playgroud)
我做错了什么导致选择器无法触发?
我在 NgRx 工作,收到此错误:
“预期有一个赋值或函数调用,但看到的是一个表达式。”
中的声纳问题this.sfForm.get('code')?.[this._mode ? 'disable' : 'enable']();。
我不明白来自声纳的消息,也不明白这里要解决什么问题。我需要一些帮助来理解代码并解决问题。
<mat-form-field [formGroup]="sfForm">
<input Input
matInput
(keydown.enter)="search($event.target.value)"
[type]="''"
formControlName="code"
required>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
sfForm: FormGroup;
private _mode: boolean = true;
public set scanMode(value: boolean) {
this._mode = value;
this.sfForm.get('code')?.[this._mode ? 'disable' : 'enable']();
}
Run Code Online (Sandbox Code Playgroud) 我正在 Angular 14 应用程序中开发 @ngRx/store 包。我想做的是创建一个可以保存基本对象数组的基本存储。我的操作文件如下所示:
import { Product } from 'src/app/data-models/product-data-models';
import { ActionType } from "./../store.config";
export const loadProducts = createAction(ActionType.LOAD_PRODUCTS);
export const loadProductsSuccess = createAction(
ActionType.LOAD_PRODUCTS_SUCCESS,
props<{ payload: Product[] }>
);
export const loadProductsFailure = createAction(
ActionType.LOAD_PRODUCTS_FAILURE,
props<{ error: string }>
);
Run Code Online (Sandbox Code Playgroud)
我的减速器文件如下所示:
import { createReducer, on } from '@ngrx/store';
import { Product } from 'src/app/data-models/product-data-models';
import { loadProducts, loadProductsSuccess, loadProductsFailure } from './product.action';
export interface ProductsState {
products: Product[];
error: string | null;
status: 'loading' | …Run Code Online (Sandbox Code Playgroud) 我开始学习 ngRx 并且遇到了基本问题。在我的课堂上,我有:
@select() todos;
Run Code Online (Sandbox Code Playgroud)
然后,当我按下按钮时,我想过滤该数据并返回 html 过滤数据。尝试过类似的东西
public onSubmit(): void {
const example = this.todos.filter(todo => todo.lang === 'pl');
console.log(example);
Run Code Online (Sandbox Code Playgroud)
}
但我收到错误:
错误 TypeError:this.todos.filter 不是函数
有人有什么想法吗?
ngrx ×6
angular ×5
redux ×2
typescript ×2
ngrx-effects ×1
ngrx-store ×1
polling ×1
rxjs ×1
timer ×1