无法读取 DashboardComponent 未定义的 属性 'pipe'
Cannot read property 'pipe' of undefined at DashboardComponent
我不断收到以下错误:
ERROR TypeError: Cannot read property 'pipe' of undefined at DashboardComponent.push../src/app/dashboard/dashboard.component.ts.DashboardComponent.getReferredUsers
我的代码如下:
ngOnInit() {
this.ngxLoader.start();
this.isMobile = this.breakpointObserver.observe([Breakpoints.Handset]);
this.campaignMode = environment.campaignMode;
this.anonymousPhotoURL = 'https://i.imgflip.com/1slnr0.jpg';
this.user = JSON.parse(localStorage.getItem('user'));
this.userService.getUserById(this.user.uid).subscribe(result => {
if (result) {
this.setUser(result);
this.createReferralUrls();
this.calculateNoOfUsers();
this.calculateRanking();
this.getReferredUsers();
this.ngxLoader.stop();
}
});
}
这里发生错误:
getReferredUsers() {
this.invitees$ = this.userService.getReferredUsers(this.userData.referralId).pipe(map(result => {
return result;
}));
}
ReferralService 中的方法如下所示:
getReferredUsers(referralId) {
if (referralId) {
return this.afs.collection('users', ref => ref.where('referredBy', '==', referralId).limit(3)).valueChanges();
}
}
我该如何解决?
当 referralId
为 falsy
时,getReferredUsers
return 未定义。
调试getReferredUsers
的输入是什么。如果它是 0、''、false、null、undefined 等,并且这些都是有效的情况,那么你应该 return 某种空的可观察对象,这样调用者就不会因 undefined 而失败。
我不断收到以下错误:
ERROR TypeError: Cannot read property 'pipe' of undefined at DashboardComponent.push../src/app/dashboard/dashboard.component.ts.DashboardComponent.getReferredUsers
我的代码如下:
ngOnInit() {
this.ngxLoader.start();
this.isMobile = this.breakpointObserver.observe([Breakpoints.Handset]);
this.campaignMode = environment.campaignMode;
this.anonymousPhotoURL = 'https://i.imgflip.com/1slnr0.jpg';
this.user = JSON.parse(localStorage.getItem('user'));
this.userService.getUserById(this.user.uid).subscribe(result => {
if (result) {
this.setUser(result);
this.createReferralUrls();
this.calculateNoOfUsers();
this.calculateRanking();
this.getReferredUsers();
this.ngxLoader.stop();
}
});
}
这里发生错误:
getReferredUsers() {
this.invitees$ = this.userService.getReferredUsers(this.userData.referralId).pipe(map(result => {
return result;
}));
}
ReferralService 中的方法如下所示:
getReferredUsers(referralId) {
if (referralId) {
return this.afs.collection('users', ref => ref.where('referredBy', '==', referralId).limit(3)).valueChanges();
}
}
我该如何解决?
referralId
为 falsy
时,getReferredUsers
return 未定义。
调试getReferredUsers
的输入是什么。如果它是 0、''、false、null、undefined 等,并且这些都是有效的情况,那么你应该 return 某种空的可观察对象,这样调用者就不会因 undefined 而失败。