Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 下一步如何修复错误不是角度的函数_Javascript_Angular_Typescript - Fatal编程技术网

Javascript 下一步如何修复错误不是角度的函数

Javascript 下一步如何修复错误不是角度的函数,javascript,angular,typescript,Javascript,Angular,Typescript,代码如下: async ngOnInit() { @Select(UserPageState.get('collection')) users$: BehaviorSubject<Array<Partial<User>>>; const USER = this.creds.credentials['id']; this.users$.subscribe(param => this.users$.next(param.filte

代码如下:

async ngOnInit() {
    @Select(UserPageState.get('collection')) users$: BehaviorSubject<Array<Partial<User>>>;


    const USER = this.creds.credentials['id'];
    this.users$.subscribe(param => this.users$.next(param.filter(x => x.id !== USER)));

    await this.store.dispatch(new UserPageList({ start: 1, length: this.pageSize })).toPromise();
    }
user.ts

用户名:字符串;
密码?:字符串;
令牌:字符串;
化身:字符串;
名字:字符串;
lastName:string;
电子邮件:字符串;
部门:字符串;
位置:字符串;
角色:字符串;
状态:字符串;
启用:布尔值;
组:阵列;
位置:阵列;
每次运行应用程序时,错误总是“下一步”不是函数。 我尝试将行为主体更改为行为主体(数组>)

我所有的代码都是错误的。

似乎您正在使用库进行状态管理,使用它的
Select
decorator来检索状态片段

@Select
返回简单的
可观察的
,而不是
行为主体
。 你的声明应该是:

@Select(UserPageState.get('collection'))users$:可观察;
或者使用
Partial[]
,但我没有您实现的详细信息

因此,如果您只想筛选此选择器检索到的用户:

导出类组件{
@选择(UserPageState.get('collection'))users$:可观察;
filteredUsers$:可观察;
恩戈尼尼特(){
const USER=this.creds.credentials['id'];
this.filteredUsers=this.users$.pipe(
映射(用户=>users.filter(用户=>user.id!==user))
);
dispatch(newuserpagelist({start:1,length:this.pageSize}));
}
}
在模板中:

    {{user.name}

注意,您应该考虑创建<强>专用选择器< /强>,并在您的商店中添加<代码>用户< /代码>。

看来,您正在使用库进行状态管理,其<代码>选择< /COD>装饰器检索一个状态切片。

@Select
返回简单的
可观察的
,而不是
行为主体
。 你的声明应该是:

@Select(UserPageState.get('collection'))users$:可观察;
或者使用
Partial[]
,但我没有您实现的详细信息

因此,如果您只想筛选此选择器检索到的用户:

导出类组件{
@选择(UserPageState.get('collection'))users$:可观察;
filteredUsers$:可观察;
恩戈尼尼特(){
const USER=this.creds.credentials['id'];
this.filteredUsers=this.users$.pipe(
映射(用户=>users.filter(用户=>user.id!==user))
);
dispatch(newuserpagelist({start:1,length:this.pageSize}));
}
}
在模板中:

    {{user.name}

注意,您应该考虑创建<强>专用选择器< /强>,并在您的商店中添加<代码>用户< /代码>。

像这样尝试。可能是工作 从“rxjs”导入{of,Subject,Observable}

  private users$= new Subject<void>();
 onusers$: Observable<void>;


 this.onusers$ = this.users$.asObservable();


   this.users$.next(param:{param.filter(x => x.id !== USER))});
private users$=new Subject();
ONUSER$:可观察到;
this.onusers$=this.users$.asObservable();
this.users$.next(参数:{param.filter(x=>x.id!==USER))});

像这样试试。可能是工作 从“rxjs”导入{of,Subject,Observable}

  private users$= new Subject<void>();
 onusers$: Observable<void>;


 this.onusers$ = this.users$.asObservable();


   this.users$.next(param:{param.filter(x => x.id !== USER))});
private users$=new Subject();
ONUSER$:可观察到;
this.onusers$=this.users$.asObservable();
this.users$.next(参数:{param.filter(x=>x.id!==USER))});

什么是
@Select(UserPageState.get('collection'))
?在哪里设置
users$
?如果你从某个主题的订阅中向该主题发送一个值,这难道不会导致堆栈溢出吗?@KurtHamilton显然存在一些设计缺陷:D.我不知道什么是
@Select
,但显然不是角度注释1。需要使用初始值初始化BehaviorSubject。2.最好将
this.users$.subscribe
替换为
this.users$.asObservable().subscribe
。3.正如其他人所提到的,这里有一个根本性的缺陷。订阅一个可观察对象并在其内部更新它会创建一个循环锁并导致错误。@Michael D,请澄清为什么建议在此处使用
asObservable()
。什么是
@Select(UserPageState.get('collection'))
?在哪里设置
users$
?如果你从某个主题的订阅中向该主题发送一个值,这难道不会导致堆栈溢出吗?@KurtHamilton显然存在一些设计缺陷:D.我不知道什么是
@Select
,但显然不是角度注释1。需要使用初始值初始化BehaviorSubject。2.最好将
this.users$.subscribe
替换为
this.users$.asObservable().subscribe
。3.正如其他人所提到的,这里有一个根本性的缺陷。订阅一个可观察对象并在其内部更新它会创建一个循环锁并导致错误。@Michael D,请澄清为什么建议在此处使用
asObservable()
。我应该将
放置在何处等待this.store.dispatch(新的UserPageList({start:1,length:this.pageSize})).toPromise()我更新了我的答案,因为我认为我更了解您的问题。但是我建议你阅读[docs]和[Angular],我应该把
放在哪里等待这个.store.dispatch(new UserPageList({start:1,length:this.pageSize})).toPromise();
我更新了我的答案,因为我认为我更了解你的问题。但是我建议你阅读[docs]和[Angular]。
  private users$= new Subject<void>();
 onusers$: Observable<void>;


 this.onusers$ = this.users$.asObservable();


   this.users$.next(param:{param.filter(x => x.id !== USER))});