尝试打开角度材料对话框时出现Angular7 Modal StaticInjectorError

时间:2019-04-03 14:13:52

标签: angular angular-material-7

每次单击def round_to_nearest_9(number): number_of_fixed_digits = 1 factor = max(10, math.pow(10, math.floor(math.log10(number)) - number_of_fixed_digits)) return (number - 1 // factor) * factor - 1 时,都会出现以下错误。

UserProfileDialog是我的对话框组件,

Modal Button

我在这里尝试了所有相关的解决方案,但是没有一个能正常工作。

Error: StaticInjectorError(AppModule)[UserProfileDialog -> InjectionToken MatDialogData]: StaticInjectorError(Platform: core)[UserProfileDialog -> InjectionToken MatDialogData]: NullInjectorError: No provider for InjectionToken MatDialogData! at NullInjector.push../node_modules/@angular/ ,这是我列出所有用户的表格,单击行上的按钮时,该表格应显示该用户的完整个人资料

dashboard.component.ts

viewUserProfile(userId: string){ const dialogRef = this.dialog.open(UserProfileDialog); dialogRef.afterClosed().subscribe(result => { console.log(`Dialog result: ${result}`); }); } @Component({ selector: 'user-profile-dialog', templateUrl: './user-profile.component.html', // styleUrls: ['./dashboard.component.scss'] }) export class UserProfileDialog { constructor( public dialogRef: MatDialogRef<UserProfileDialog>, @Inject({'data':'MAT_DIALOG_DATA'}) public data: any) {} onNoClick(): void { this.dialogRef.close(); } }

app.module.ts

1 个答案:

答案 0 :(得分:1)

在app.module(或任何导入材料模块的位置)中,将MAT_DIALOG_DATA添加到从@ angular / material导入的数据中

import { MAT_DIALOG_DATA } from '@angular/material'


将其添加到您的app.module提供程序

@NgModule({
  providers: [ { provide: MAT_DIALOG_DATA, useValue: [] } ]
})
相关问题