Angular Material’s documentation says:
import { MatSlideToggleModule } from '@angular/material/slide-toggle';
@NgModule ({
imports: [
MatSlideToggleModule,
]
})
class AppModule {}
But Angular 17 doesn’t create app.module file by default. Is there any way to do that without app.module?
2
Answers
Angular v17 onwards, standalone is default via CLI
Which means when you create new project it wont have any modules in it
As a workaround it is possible to create a module-based app by using the
--no-standalone
flag :ng new --no-standalone
which will create a app.modules.ts in your projectuse this command :
Follow it up with :
Then import relevent modules from angular material to your project app.module.ts :
import dependencies into the component instead of app.modules, add attribute standalone:true , like the code below: