Arrays 迭代ngrx8约化器
接口:Arrays 迭代ngrx8约化器,arrays,angular,redux,ngrx,ngrx-reducers,Arrays,Angular,Redux,Ngrx,Ngrx Reducers,接口: export interface IClient extends Array<IClient> { client_name: string } )) 影响: addClient = createEffect(() => { return this.actions.pipe( ofType(ClientActionTypes.addClient), switchMap(({ client }) => { retu
export interface IClient extends Array<IClient> {
client_name: string
}
))
影响:
addClient = createEffect(() => {
return this.actions.pipe(
ofType(ClientActionTypes.addClient),
switchMap(({ client }) => {
return this.clientService.addClient(client).pipe(
map((res) => ClientActionTypes.addClientSuccess(res)),
catchError(error => {
return of(ClientActionTypes.addClientFailure({ error }))
})
);
})
);
});
在上面的代码中,我试图将数组附加到client_name中,但是我输入的值在数组中被分成多个值,我已经附加了redux存储,说明了它是如何被迭代的
例如,如果我输入了test和testing,它应该打印一个['test',“testing”]您做错了
数组
。这是一个简单的字符串
导出接口IClient{
客户端名称:字符串;
}
客户端名称**s**:IClient[]
导出接口ClientState{
客户名称:IClient[]
}
export const clientInitialState:ClientState={
客户名称:[]
}
export const clientReducer=createReducer(
客户初始状态,
on(ClientActionTypes.addClientSuccess,(状态,操作)=>({
……国家,
客户端名称:[…state.client\u名称,action.client\u名称]
})
addClient$=createEffect(()=>{
返回此.actions.pipe(
类型(ClientActionTypes.addClient),
开关映射((操作)=>{
返回此.clientService.addClient(action.client\u name).pipe(
map((res)=>ClientActionTypes.addClientSuccess({client_name:res})),
catchError(错误=>{
返回(ClientActionTypes.addClientFailure({error}))
})
);
})
);
});
- 抱歉,使用了
而不是代码块格式,因此4个空格由于某些原因无法正常工作code
export interface ClientState {
client_name: IClient[]
}
export const clientInitialState: ClientState = {
client_name: []
}
export const clientReducer = createReducer(
clientInitialState,
on(ClientActionTypes.addClientSuccess,(state, {client_name}) => ({
...state,
client_name: [...client_name]
})
addClient = createEffect(() => {
return this.actions.pipe(
ofType(ClientActionTypes.addClient),
switchMap(({ client }) => {
return this.clientService.addClient(client).pipe(
map((res) => ClientActionTypes.addClientSuccess(res)),
catchError(error => {
return of(ClientActionTypes.addClientFailure({ error }))
})
);
})
);
});