如何与主体中的受试者正确刷新变型列表
我有两个列表可以刷新两个不同的事件(一个帖子,一个删除)。问题是,当调用删除时,它也称为邮政方法。因此,我删除了某个问题,但是帖子重新发布了:p
刷新列表是profileSer $和ptofilelistcistinct $
初始化:
export class UserEditComponent implements OnInit {
userId: string = "";
currentUser$!: Observable<User>;
profileUser$!: Observable<ProfileUser[]>;
profileListDistinc$!: Observable<Profile[]>;
constructor(
private activatedRoute: ActivatedRoute,
private router: Router,
private userService: UserService,
private profileService: ProfileService,
private reloadProfile: SearchEmitterService,
private confirmDialogService: ConfirmDialogService
) { }
ngOnInit(): void {
const id = this.activatedRoute.snapshot.paramMap.get('id');
this.userId = id ? id : "";
this.currentUser$ = this.userService.getUser(this.userId);
this.profileUser$ = this.reloadProfile.reloadprofileUserBehavior$.pipe(
switchMap(
x => this.profileService.getProfilesForUser(this.userId)));
this.profileListDistinc$ = this.reloadProfile.reloadProfileListDisctincBehavior$.pipe(
switchMap(x => this.profileService.getProfilesDisctinc(this.userId)));
}
post方法:
onAddProfileUser(profileId: string, userId: string) {
let newProfileUser: ProfileUserCreate = {
profileId: profileId,
userId: userId
}
this.profileService.addProfileForUser(newProfileUser)
.subscribe(x => {
this.reloadProfile.reloadprofileUserBehavior$.next(null);
this.reloadProfile.reloadProfileListDisctincBehavior$.next(null);
});
}
delete方法:
onDeleteProfileUser(profileUser: ProfileUser): void {
this.profileService.deleteProfileForUser(profileUser)
.subscribe(x => {
this.reloadProfile.reloadProfileListDisctincBehavior$.next(null);
this.reloadProfile.reloadprofileUserBehavior$.next(null);
});
}
重新加载服务:
export class SearchEmitterService {
reloadProfileListDisctincBehavior$: BehaviorSubject<any> = new BehaviorSubject<any>(null);
reloadprofileUserBehavior$: BehaviorSubject<any> = new BehaviorSubject<any>(null);
constructor() { }
I have two list to refresh for two different event (one post, one delete). The issue is that when delete is called, It calls also the post method. So I delete someting, but the post re-post it :p
The lists to refresh are the profileUser$ and the ptofileListDistinct$
Initialization:
export class UserEditComponent implements OnInit {
userId: string = "";
currentUser$!: Observable<User>;
profileUser$!: Observable<ProfileUser[]>;
profileListDistinc$!: Observable<Profile[]>;
constructor(
private activatedRoute: ActivatedRoute,
private router: Router,
private userService: UserService,
private profileService: ProfileService,
private reloadProfile: SearchEmitterService,
private confirmDialogService: ConfirmDialogService
) { }
ngOnInit(): void {
const id = this.activatedRoute.snapshot.paramMap.get('id');
this.userId = id ? id : "";
this.currentUser$ = this.userService.getUser(this.userId);
this.profileUser$ = this.reloadProfile.reloadprofileUserBehavior$.pipe(
switchMap(
x => this.profileService.getProfilesForUser(this.userId)));
this.profileListDistinc$ = this.reloadProfile.reloadProfileListDisctincBehavior$.pipe(
switchMap(x => this.profileService.getProfilesDisctinc(this.userId)));
}
Post Method:
onAddProfileUser(profileId: string, userId: string) {
let newProfileUser: ProfileUserCreate = {
profileId: profileId,
userId: userId
}
this.profileService.addProfileForUser(newProfileUser)
.subscribe(x => {
this.reloadProfile.reloadprofileUserBehavior$.next(null);
this.reloadProfile.reloadProfileListDisctincBehavior$.next(null);
});
}
Delete Method:
onDeleteProfileUser(profileUser: ProfileUser): void {
this.profileService.deleteProfileForUser(profileUser)
.subscribe(x => {
this.reloadProfile.reloadProfileListDisctincBehavior$.next(null);
this.reloadProfile.reloadprofileUserBehavior$.next(null);
});
}
Reload Service:
export class SearchEmitterService {
reloadProfileListDisctincBehavior$: BehaviorSubject<any> = new BehaviorSubject<any>(null);
reloadprofileUserBehavior$: BehaviorSubject<any> = new BehaviorSubject<any>(null);
constructor() { }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论