title: Keycloak-angular (keycloak.js) returns "Cannot read property 'resourceAccess' of undefined"
body: <p>I am using "keycloak-angular": "^7.1.0" and "keycloak-js": "^9.0.0". It seems that initialization goes ok. Whenever I am going to protected URL, angular redirects me to Keycloak, I am able to log in and I see cookies with tokens.</p>
  
  <p>However, I get a problem whenever I call any of KeycloakService methods it returns an error: "Cannot read property '(method name here)' of undefined".</p>
  
  <p>What I am doing wrong here? Here are my classes:</p>
  
  <p>App module:</p>
  
  <pre><code>import { BrowserModule } from '@angular/platform-browser';
  import { NgModule, DoBootstrap, ApplicationRef } from '@angular/core';
  import {HttpClientModule, HTTP_INTERCEPTORS} from '@angular/common/http';
  import {ReactiveFormsModule} from '@angular/forms';
  import { AppRoutingModule } from './app-routing.module';
  import { AppComponent } from './app.component';
  import { NavbarComponent } from './navbar/navbar.component';
  import { AuthGuard } from './services/kecloak/auth.guard';
  import { KeycloakAngularModule, KeycloakService } from 'keycloak-angular';
  import { environment } from 'src/environments/environment';
  import { KeycloakInitService } from './services/kecloak/keycloak.init';
  
  const keycloakService = new KeycloakService();
  
  @NgModule({
    declarations: [
      ...
    ],
    imports: [
      BrowserModule,
      AppRoutingModule,
      HttpClientModule,
      ReactiveFormsModule,
      NoopAnimationsModule,
      KeycloakAngularModule
    ],
    providers: [
      ...
      AuthenticationService,
      {
        provide:HTTP_INTERCEPTORS,
        useClass:AuthenticationInterceptor,
        multi:true
      },
      AuthGuard,
      {
        provide: KeycloakService,
        useValue: keycloakService
      }
    ],
    bootstrap: [AppComponent],
    entryComponents: [AppComponent]
  })
  
  export class AppModule implements DoBootstrap {
    ngDoBootstrap(appRef: ApplicationRef) {
      console.info(keycloakService + "initiated")
      keycloakService
        .init({
          config: environment.keycloak,
          initOptions: {
            checkLoginIframe: false
          },
          bearerExcludedUrls: []
        })
        .then(() =&gt; {
          console.log('[ngDoBootstrap] bootstrap app');
  
          appRef.bootstrap(AppComponent);
        })
        .catch(error =&gt; console.error('[ngDoBootstrap] init Keycloak failed', error));
    }
  }
  </code></pre>
  
  <p>Navbar component:</p>
  
  <pre><code>import { Component, OnInit, OnChanges, SimpleChanges, Input, ChangeDetectionStrategy } from '@angular/core';
  import { Router } from '@angular/router';
  import { KeycloakService } from 'keycloak-angular';
  
  @Component({
    selector: 'app-navbar',
    templateUrl: './navbar.component.html',
    styleUrls: ['./navbar.component.css']
  })
  export class NavbarComponent implements OnInit {
    public loggedIn:boolean;
    public signInText:string;
    private roles:string[];
    private router:Router;
    private keycloak:KeycloakService;
  
    @Input() isAdmin:boolean=false;
    constructor( router:Router, keycloak: KeycloakService) { 
      this.router=router;
      this.keycloak = keycloak;
    }
  
    async ngOnInit() {
      console.info(this.keycloak)
      this.keycloak.isLoggedIn().then(data=&gt;{
        this.loggedIn=data;
        if(this.loggedIn){this.statusLogedIn();}
        else{this.statusLogedOut();}
      });
  
      if(this.keycloak.isLoggedIn){
      this.statusLogedIn(); 
      }
      else {
      this.statusLogedOut();
      }
    }
  
    public login() {
      console.info(this.keycloak)
      if(!this.loggedIn){
        this.keycloak.login();
      }
      else{
        this.keycloak.logout();
        this.keycloak.clearToken();
        this.statusLogedOut();
      }
    }
  
  
    statusLogedIn(){
     this.roles = this.keycloak.getUserRoles(true);
      this.loggedIn=true;
      this.signInText='Log out';
    }
    statusLogedOut(){
      this.loggedIn=false;
        this.signInText='Sign In';
  
    }
  }
  
  </code></pre>
  
  <p>Configuration:</p>
  
  <pre><code>
  import { KeycloakConfig } from 'keycloak-angular';
  
  // Add here your keycloak setup infos
  const keycloakConfig: KeycloakConfig = {
    url: 'http://localhost:8080/auth/',
    realm: 'master',
    clientId: 'angular-client'
  };
  
  export const environment = {
    production: false,
    ...
    keycloak: keycloakConfig
  };
  
  </code></pre>