app.component.ts 1.03 KB
import {Component, NgZone} from '@angular/core';
import {Router} from '@angular/router';
import {MatDialog, MatDialogConfig} from "@angular/material";
import {LoginComponent} from "./modules/login/login-component/login.component";

declare var window: any;

@Component({
  selector: 'moya-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {

  constructor(private router: Router, private zone: NgZone, private dialog: MatDialog) {

    window.angularRoute = (url => {
      zone.run(() => {
        router.navigateByUrl(url);
      });
    });

  }

  openLoginDialog(): void  {

    let conf = new MatDialogConfig();

    conf.autoFocus = true;
    /*conf.height = "800px";
    conf.width = "500px";*/

    let dialogRef = this.dialog.open(LoginComponent, conf);

    dialogRef.componentInstance.loginEvent.subscribe((success) => {
      if(success) {
        dialogRef.close();
      } else {
        dialogRef.close();
        this.router.navigateByUrl("/login");
      }
    });
  }


}