0

我在下面的相同配置在一天之前工作正常,并且在我的机器上不再工作。我检查了其他机器,它在这些机器上仍然可以正常工作。这就是我正在做的事情。

应用路由:

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;
      }

数据提供者:

@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。 错误截图

问题:

  1. 这个配置正确还是我遗漏了什么?

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

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

更新:

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

AppComponent 请求 UserConfigsService 但获得 DataProviderService。

复制 GitHub 链接

4

0 回答 0