File

apps/demo/src/app/app.component.ts

Implements

OnDestroy OnInit

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector app-root
templateUrl ./app.component.html

Index

Properties
Methods

Constructor

constructor(_langService: LangService, _authService: AuthService, _tokenService: TokenService, _translateService: TranslateService, _bsLocaleService: BsLocaleService, _metaService: MetaService, _authModalService: AuthModalService, _platformId: Object)
Parameters :
Name Type Optional
_langService LangService No
_authService AuthService No
_tokenService TokenService No
_translateService TranslateService No
_bsLocaleService BsLocaleService No
_metaService MetaService No
_authModalService AuthModalService No
_platformId Object No

Methods

ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
onError
onError(error: any)
Parameters :
Name Type Optional
error any No
Returns : void
onInfo
onInfo()
Returns : void
onOauthSignInSuccess
onOauthSignInSuccess(modal: AuthModalComponent, data: RedirectUrlDto)
Parameters :
Name Type Optional
modal AuthModalComponent No
data RedirectUrlDto No
Returns : void
onSignIn
onSignIn()
Returns : void
onSignInError
onSignInError(modal: AuthModalComponent, error: any)
Parameters :
Name Type Optional
modal AuthModalComponent No
error any No
Returns : void
onSignInOrInfoSuccess
onSignInOrInfoSuccess(modal: AuthModalComponent, data: UserTokenDto)
Parameters :
Name Type Optional
modal AuthModalComponent No
data UserTokenDto No
Returns : void
onSignOut
onSignOut()
Returns : void
onSignOutSuccess
onSignOutSuccess(modal: AuthModalComponent)
Parameters :
Name Type Optional
modal AuthModalComponent No
Returns : void

Properties

Private _destroyed$
Type : Subject<boolean>
Default value : new Subject<boolean>()
Public currentUser$
Type : Observable<User>
navbar
Type : NavbarComponent
Decorators :
@ViewChild('navbar')
Public title
Type : string
import { isPlatformBrowser } from '@angular/common';
import { ChangeDetectionStrategy, Component, Inject, OnDestroy, OnInit, PLATFORM_ID, ViewChild } from '@angular/core';
import { MetaService } from '@ngx-meta/core';
import { TranslateService } from '@ngx-translate/core';
import {
  AuthModalComponent,
  AuthModalService,
  AuthService,
  LangService,
  RedirectUrlDto,
  TokenService,
  User,
  UserTokenDto
} from '@rucken/core';
import { NavbarComponent } from '@rucken/web';
import { BindIoInner } from 'ngx-bind-io';
import { defineLocale } from 'ngx-bootstrap/chronos';
import { BsLocaleService } from 'ngx-bootstrap/datepicker';
import { enGbLocale, ruLocale } from 'ngx-bootstrap/locale';
import { Observable, Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { APP_ROUTES } from './app.routes';
import { config } from './config/config';

defineLocale('ru', ruLocale);
defineLocale('en', enGbLocale);
@BindIoInner()
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class AppComponent implements OnDestroy, OnInit {
  @ViewChild('navbar')
  navbar: NavbarComponent;
  public title: string;
  public currentUser$: Observable<User>;
  private _destroyed$: Subject<boolean> = new Subject<boolean>();

  constructor(
    private _langService: LangService,
    private _authService: AuthService,
    private _tokenService: TokenService,
    private _translateService: TranslateService,
    private _bsLocaleService: BsLocaleService,
    private _metaService: MetaService,
    private _authModalService: AuthModalService,
    @Inject(PLATFORM_ID) private _platformId: Object
  ) {
    this._authModalService.signInInfoMessage = config.authModal.signInInfoMessage;
    this._authModalService.signUpInfoMessage = config.authModal.signUpInfoMessage;
    this.currentUser$ = this._authService.current$;
    this._langService.current$.pipe(takeUntil(this._destroyed$)).subscribe(lang => {
      if (lang) {
        this._bsLocaleService.use(lang);
        this._metaService.setTag('og:locale', lang.toLowerCase() + '-' + lang.toUpperCase());
        this.title = this._translateService.instant(this._metaService.loader.settings.applicationName);
      }
    });
    this._tokenService.tokenHasExpired$.pipe(takeUntil(this._destroyed$)).subscribe(result => {
      if (result === true) {
        if (isPlatformBrowser(this._platformId)) {
          this._authModalService.onTokenError();
        } else {
          this._authModalService.onSignOutSuccess(undefined);
        }
      }
    });
  }
  ngOnInit() {
    this._authModalService.onInfo();
    this.navbar.setRoutes(APP_ROUTES);
  }
  ngOnDestroy() {
    this._destroyed$.next(true);
    this._destroyed$.complete();
  }
  onInfo() {
    this._authModalService.onInfo();
  }
  onSignOut() {
    this._authModalService.onSignOut();
  }
  onSignIn() {
    this._authModalService.onSignIn();
  }
  onOauthSignInSuccess(modal: AuthModalComponent, data: RedirectUrlDto) {
    this._authModalService.onOauthSignInSuccess(modal, data);
  }
  onSignInOrInfoSuccess(modal: AuthModalComponent, data: UserTokenDto) {
    this._authModalService.onSignInOrInfoSuccess(modal, data);
  }
  onSignOutSuccess(modal: AuthModalComponent) {
    this._authModalService.onSignOutSuccess(modal);
  }
  onError(error: any) {
    this._authModalService.onError(error);
  }
  onSignInError(modal: AuthModalComponent, error: any) {
    this._authModalService.onSignInError(modal, error);
  }
}
<navbar
    [title]="title"
    [showSignIn]="!(currentUser$ | async)"
    [showSignOut]="currentUser$ | async"
    (signIn)="onSignIn()"
    (signOut)="onSignOut()"
    #navbar></navbar>
<router-outlet></router-outlet>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""