未捕获(承诺):TypeError:guard不是函数-当类扩展另一个类时

时间:2018-09-21 05:45:08

标签: angular authentication typeerror canactivate auth-guard

我下面使用的相同配置在一天之前就可以正常工作,并且在我的计算机上不再工作。我检查了其他机器,但在那些机器上仍能正常工作。这是我在做什么。

应用程序路由:

const routes: Routes = [
{
    path: AppRoutes.WorkflowRoute,
    canActivate: [AuthGuardService, UserConfigsService],
    data: { applicationIdentifier: ApplicationIdentifiers.Workflow, route: AppRoutes.WorkflowRoute },
    loadChildren: 'app/pages/workflowexplorer/workflowexplorer.module#WorkflowexplorerModule',
}]

UserConfig服务:(如您所见,它替代了DataProviderService)

@Injectable({
  providedIn: 'root'
})
export class UserConfigsService extends DataProviderService implements CanActivate {
      private controllerName: string = '/UserConfigs/';
      private userCofigs: UserCofig[];
      private userConfigsUpdatedSource = new Subject<boolean>();
      userConfigsUpdated = this.userConfigsUpdatedSource.asObservable();
      private dataSubject = new ReplaySubject<UserCofig[]>();

      canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean | Observable<boolean> | Promise<boolean> {
        if (this.authService.isLoggedIn()) {
          const applicationIdentifier = route.data['applicationIdentifier'] as number;
          this.getUserConfigsForApplication(applicationIdentifier).subscribe((response) => {
            this.userCofigs = <UserCofig[]>response;
          }, error => console.log(`Error : ${error}`));
        }
        return true;
      }

DataProvider:

@Injectable({
  providedIn: 'root'
})
export class DataProviderService {
    private baseUrl: string = '';
    private apiVersion: string = '';
    private commomErrorMessage: string = 'Something went wrong please try again';

    constructor(public http: HttpClient,
        private appConfigurationService: AppConfigurationService,
        private messageDialogService: MessageDialogService,
        private spinnerService: SpinnerService,
        public authService: AuthService
    ) {
        this.baseUrl = this.appConfigurationService.getPreDefineBaseUrl();
        this.apiVersion = `v${this.appConfigurationService.getPreDefineApiVersion()}`;
    }

如错误所示,对于UserConfigsService,防护设置为不实现canActivate的DataProvideService。 Error Screenshot

问题:

  1. 此配置正确还是缺少任何内容?

  2. 不明白为什么相同的配置在我的其他机器上也可以工作?

  3. 有什么我应该尝试不同的方法吗?

更新

进一步深入研究后,我发现每次注入UserConfigsService时,都会返回DataProviderService对象。我不知道为什么。

AppComponent向UserConfigsService询问,但获得了DataProviderService。

Reproduction GitHub Link

0 个答案:

没有答案