问题描述: 在使用Angular和Google Cloud Firebase Auth时,我们可能会遇到在延迟加载模块中使用自定义声明的问题。当我们使用延迟加载模块时,自定义声明可能无法正确加载,这意味着我们在检查用户是否具有自定义声明时会遇到问题。
解决方案: 为了解决这个问题,我们可以使用Angular的Injector服务。这个服务可以在运行时动态获取依赖项,这对于延迟加载模块非常有用。具体步骤如下:
import {Injectable, Injector} from '@angular/core'; import {AuthService} from '../auth/auth.service';
@Injectable({ providedIn: 'root' }) export class CustomClaimsService { private auth: AuthService;
constructor(private injector: Injector) { }
getCustomClaims(): Promise
import {Component, OnInit} from '@angular/core'; import {CustomClaimsService} from '../custom-claims/custom-claims.service';
@Component({
selector: 'app-lazy-loaded-component',
template:
})
export class LazyLoadedComponent implements OnInit {
private customClaimsService: CustomClaimsService;
private isCustomClaimEnabledFlag =