我有一个由导航组件启动的材料(如果有的话),但是问题是我正在使用对话框进行登录,并且在登录成功并将用户重定向到{{1}时,它似乎没有关闭。 }
dashboard.html
这是我在dashboard.ts中的代码
因此,它应该在到达组件页面时触发关闭对话框。但是它没有关闭对话框,因此无法显示仪表板。我也没有收到任何控制台错误,所以我不太确定出了什么问题。
我还尝试调用import { Component, OnInit } from '@angular/core';
import {Observable} from 'rxjs';
import {map} from 'rxjs/operators';
import { AngularFireAuth } from "@angular/fire/auth";
import { AuthService } from "../../core/services/auth.service";
import { User, PrivateUser } from "../../core/models/user";
import { UserService } from "../../core/services/user.service";
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { SignUpComponent } from '../../components/authentication/sign-up/sign-up.component';
import { SignInComponent } from '../../components/authentication/sign-in/sign-in.component';
@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.css']
})
export class DashboardComponent implements OnInit {
isLoggedIn$: Observable<boolean>;
isLoggedOut$: Observable<boolean>;
user$: Observable<any>;
constructor(
public afAuth: AngularFireAuth,
private authService: AuthService,
private userService: UserService,
public dialog: MatDialog,
public dialogRef: MatDialogRef<SignInComponent>
) { }
ngOnInit() {
this.dialogRef.close();
this.isLoggedIn$ = this.afAuth.authState.pipe(map(user => !!user));
this.isLoggedOut$ = this.isLoggedIn$.pipe(map(loggedIn => !loggedIn));
this.user$ = this.authService.user$;
}
来加载仪表板,但对话框仍未关闭。
这是SignInComponent触发的地方
this.dialog.closeAll;
在我的html上
loginModal() {
this.dialog.open(SignInComponent)
};
}
答案 0 :(得分:0)
将mat-dialog-close
添加到您的关闭按钮。
<mat-dialog-actions>
<button mat-button mat-dialog-close>No</button>
<!-- The mat-dialog-close directive optionally accepts a value as a result for the dialog. -->
<button mat-button [mat-dialog-close]="true">Yes</button>
</mat-dialog-actions>