-1

I would like to use two material ui components for my angular application. They are MatDialog, and MatDialogConfig. I'm not sure if I have something in the wrong place or not but basically all my modules work fine except this one. Both my app.module.ts file and my component course-dialog.component file have import statements with MatDialog, and MatDialogConfig, it's just not finding the module when I run the program. They are listed below. How can I go about getting my compiler to load these modules? app.module.ts

 import { NgModule, ErrorHandler } from '@angular/core';
 import { registerLocaleData } from '@angular/common';
 import { HttpClientModule } from '@angular/common/http';
 import { BrowserModule } from '@angular/platform-browser';
 import { RouteReuseStrategy } from '@angular/router';
 import {MatDialog, MatDialogConfig} from '@angular/material/dialog';
 import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
 import { SplashScreen } from '@ionic-native/splash-screen/ngx';
 import { StatusBar } from '@ionic-native/status-bar/ngx';
 import { GooglePlus } from '@ionic-native/google-plus/ngx';
 import { Facebook } from '@ionic-native/facebook/ngx';
 import { StripeModule } from "stripe-angular"
 import { AppComponent } from './app.component';
 import { AppRoutingModule } from './app-routing.module';
 import { AngularFireModule } from '@angular/fire';
 import {AngularFireAuthModule} from '@angular/fire/auth';
 import {AngularFirestoreModule} from '@angular/fire/firestore';
 import {AngularFireStorageModule} from '@angular/fire/storage';
 import { AngularFireDatabaseModule } from '@angular/fire/database';



 /*Services*/
 import { AuthService } from '@services/auth.service';
 import { CallService } from '@services/call.service';
 import { DataProvider } from '@services/data/base.data-provider';
 import { LocalDataProvider } from '@services/data/local.data- 
 provider';
 import { FirebaseDataProvider } from '@services/data/firebase.data- 
 provider';
 import { RemoteDataProvider } from '@services/data/remote.data- 
 provider';
 import { BackendlessDataProvider } from 
'@services/data/backendless.data-provider';
 import { EmailService } from '@services/email.service';
 import { FacebookApiService } from '@services/facebook-api.service';
 import { InAppBrowserService } from '@services/in-app- 
 browser.service';
 import { MapsService } from '@services/maps.service';
 import { OpenHoursService } from '@services/open-hours.service';
 import { FavoritesService } from '@services/favorites.service';

 import { Calendar } from '@ionic-native/calendar/ngx';
 import { EmailComposer } from '@ionic-native/email-composer/ngx';
 import localeDe from '@angular/common/locales/de';
 import { Config } from '../config';
 import { NgxWebstorageModule } from 'ngx-webstorage';
 registerLocaleData(localeDe, 'de');
 import { ComponentsModule } from 
 './pages/components/components.module';
 import { OneSignalModule } from './pages/push/one-signal.module';
 import { AgmCoreModule } from '@agm/core';

 import { ServiceWorkerModule } from '@angular/service-worker';
 import { environment } from '../environments/environment';

 @NgModule({
 declarations: [AppComponent],
  entryComponents: [],
  imports: [
 MatDialog,
 MatDialogConfig,
 HttpClientModule,
  BrowserModule,
  ComponentsModule,
  IonicModule.forRoot(),
   CartServiceModule.forRoot(),
   AppRoutingModule,
   AgmCoreModule.forRoot({
   apiKey: Config.mapsApiKey
    }),
NgxWebstorageModule.forRoot(),
AngularFireModule.initializeApp(Config.firebase),
AngularFireAuthModule,
AngularFirestoreModule,
AngularFireDatabaseModule,
environment.production })
 ],
providers: [
Config,
AuthGuard,

// { provide: ErrorHandler, useClass: IonicErrorHandler },
StatusBar,
{ provide: DataProvider, useClass: LocalDataProvider },
// { provide: DataProvider, useClass: FirebaseDataProvider },
// { provide: DataProvider, useClass: RemoteDataProvider },
// { provide: DataProvider, useClass: BackendlessDataProvider },
EmailService,
CallService,
InAppBrowserService,
MapsService,
OpenHoursService,
FavoritesService,
AuthService,
Calendar,
FacebookApiService,
StatusBar,
OneSignalModule,
SplashScreen,
AuthResolver,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
EmailComposer,
GooglePlus,
Facebook
],
bootstrap: [AppComponent]

}) export class AppModule {}

courses-list.component.ts

 import { AgmCoreModule } from '@agm/core';
 import { CommonModule } from '@angular/common';
 import { NgModule } from '@angular/core';
 import { IonicModule } from '@ionic/angular';
 import { CustomComponentsModule } from '@components/custom- 
 components.module';
 import { DynamicFormModule } from '@components/forms/dynamic- 
 form.module';
 import { PipesModule } from '@pipes/pipes.module';
 import { RouterModule, Routes } from '@angular/router';
 import { CoursesCardListPage } from './courses-card-list.page';
 import {MatDialog, MatDialogConfig} from '@angular/material/dialog';


 const routes: Routes = [
 {
path: '',
component: CoursesCardListPage
}
];


@NgModule({
imports: [MatDialog,MatDialogConfig,IonicModule, CommonModule, 
PipesModule, CustomComponentsModule, RouterModule.forChild(routes)],
declarations: [CoursesCardListPage],
entryComponents: [CoursesCardListPage]
})
export class CoursesCardListModule { }
evan
  • 117
  • 1
  • 10

1 Answers1

0

In your module you need to import the MatDialogModule like so:

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

The imports that you have in your files are to be used in the components.

So in your modules you should have this import:

@NgModule({
 declarations: [AppComponent],
  entryComponents: [],
  imports: [
// here is the correct import
 MatDialogModule, // instead of MatDialog and MatDialogConfig
 HttpClientModule,
  BrowserModule,
  ComponentsModule,
....

MatDialog and MatDialogConfig should be imported in the components and not in the modules.

ionut-t
  • 1,121
  • 1
  • 7
  • 14
  • that wasn't it. My error is that it is not finding the module not the reference is undefined – evan Apr 25 '20 at 21:15
  • I checked again your code. I don't see anywhere in your modules the correct import as I mentioned in my answer. I might be tired but I'm pretty sure that I can't see it. You're getting that error because you are not importing correctly. You import MatDialog instead of MatDialogModule. I'll add a small update to my answer. – ionut-t Apr 25 '20 at 21:18
  • Which import, inside the coure-list.component or the app.module? I don't think any of the mat dialog documentation says to put module at the end of matdialog. I tried putting it in and it didn't work. This is pretty weird. – evan Apr 25 '20 at 21:48
  • @evan inside the app.module or any other module where are you planning to use the MatDialog. Here is the documentation https://material.angular.io/components/dialog/api. – ionut-t Apr 25 '20 at 21:50
  • I'm not sure where I have suggested you to put module of the end of matdialog?!!( whatever that is). Just make the correct import as I wrote in the answer inside your AppModule and MatDialogModule (and any other module where you might use the dialog) and it will work. – ionut-t Apr 25 '20 at 21:57
  • It doesn't seem to be working as you put it earlier. I'm going to try again later today and let you know what i find – evan Apr 25 '20 at 21:59