I am encountering an issue with an object of type "user" that is supposed to have a function called "getPermission()". While running my Angular 7 application, I am getting the error message "TypeError: this.user.getPermission is not a function".
Here is what I believe to be the crucial context:
This is my user class:
export class User {
...
public getPermission(): boolean {
return true;
}
...
}
I have a service responsible for fetching a user from an asp.net core API:
getUser(id): Observable<User> {
return this.http.get<User>(this.baseurl + 'user/' + id);
}
Next, I have a resolver implementation:
@Injectable()
export class UserEditResolver implements Resolve<User> {
constructor(private userService: UserService, private authService: AuthService,
private router: Router,
private alertify: AlertifyService) {}
resolve(route: ActivatedRouteSnapshot): Observable<User> {
return this.userService.getUser(this.authService.decodedToken.nameid).pipe(
catchError(error => {
this.alertify.error('Problem retrieving your data');
this.router.navigate(['/users']);
return of(null);
})
);
}
}
Lastly, in my component, I make a call to the getPermission function:
user: User;
ngOnInit() {
this.route.data.subscribe(data => {
this.user = data['user'];
});
const t: boolean = this.user.getPermission();
}
Despite successfully loading properties from the API, the error "TypeError: this.user.getPermission is not a function" persists.
I would greatly appreciate any insights into why this might be happening!