简体   繁体   English

角材料StaticInjectorError:没有MatDialog的提供者

[英]Angular material StaticInjectorError: No provider for MatDialog

I am getting below error in my browser console when I launch my Angular 5 page in browser.当我在浏览器中启动我的 Angular 5 页面时,我的浏览器控制台中出现以下错误。

ERROR Error: StaticInjectorError(AppModule)[AppComponent -> MatDialog]: StaticInjectorError(Platform: core)[AppComponent -> MatDialog]: NullInjectorError: No provider for MatDialog!错误错误:StaticInjectorError(AppModule)[AppComponent -> MatDialog]:StaticInjectorError(Platform: core)[AppComponent -> MatDialog]:NullInjectorError:没有提供 MatDialog! at _NullInjector.webpackJsonp.../../../core/esm5/core.js._NullInjector.get在 _NullInjector.webpackJsonp.../../../core/esm5/core.js._NullInjector.get

What am I missing?我错过了什么?

This error usually occurs when the service you are trying to use has not been provided in your @NgModule .当您尝试使用的服务未在您的@NgModule提供时,通常会发生此错误。

To use the MatDialog service, you will need to go to your module file and add MatDialogModule to the array of imports:要使用MatDialog服务,您需要转到您的模块文件并将MatDialogModule添加到导入数组中:

import {MatDialogModule} from '@angular/material/dialog';

@NgModule({
  imports: [MatDialogModule]
})
export class MyModule {}

You can find the import along with more information on how to use the dialog here: https://material.angular.io/components/dialog/api .您可以在此处找到导入以及有关如何使用对话框的更多信息: https : //material.angular.io/components/dialog/api

有时候想打API也会出现下面的错误,这时候需要检查api对错,设置API时也要检查空格。

Uncaught (in promise): Error: StaticInjectorError(AppModule)[LoginDialogComponent -> InjectionToken MatDialogData]:

Throwing an error, if no data is supplied with @Inject(MAT_DIALOG_DATA) data: any.如果@Inject(MAT_DIALOG_DATA) data: 没有提供任何数据,则抛出错误。 Try to provide a default data.尝试提供默认数据。 Also The dialog component name should be in entryComponents in respective Module.此外,对话框组件名称应在相应模块的 entryComponents 中。

try to declare outside the Constructor and initialize inside constructor尝试在构造函数外部声明并在构造函数内部初始化

my code like this My Interface is below我这样的代码我的界面在下面

 export interface DoctorDetails { UserId:number, DoctorId:number, FirstName:string, LastName:string, Speciality:string, EmailId:string, PhoneNumber1:string, PhoneNumber2:string, CountryName:string, StateName:string, city:string, AddressLine1:string, HospitalName:string, PrimaryMark:number }

My Declaration and Initialization is like below我的声明和初始化如下

 export class DoctorDetailsComponent implements OnInit { url:string="http://hospitalapi.com/api/doctor/GetDoctor/"; doctor:DoctorDetails[];//Declare constructor(private route:ActivatedRoute, private http:HttpService ) { const id =route.snapshot.paramMap.get("id"); console.log(id); this.url = this.url+id; this.doctor = new Array<DoctorDetails>();//Initialize }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM