admin管理员组

文章数量:1135065

I have downloaded with npm the new version of Angular and I haven't seen the app.module.ts file.

Has it been eliminated from the project structure?

.

I have tried creating a new one. It seems odd.

I have downloaded with npm the new version of Angular and I haven't seen the app.module.ts file.

Has it been eliminated from the project structure?

.

I have tried creating a new one. It seems odd.

Share Improve this question edited Apr 15, 2024 at 12:57 Roy 8,0694 gold badges27 silver badges48 bronze badges asked Nov 9, 2023 at 16:14 rippleytriggerrippleytrigger 1,3652 gold badges8 silver badges7 bronze badges 5
  • 2 I have use npm install -g angular-cli. I have obtained the last version, thus I download the files through it. I'm in a course where app.module.ts is needed but I haven't have the file. – rippleytrigger Commented Nov 9, 2023 at 16:27
  • 2 Ok. But why it doesn't exist? Have been taken off in the new version? – rippleytrigger Commented Nov 9, 2023 at 16:33
  • 1 The default for --standalone is still false in the ng new command. See angular.dev/cli/new. So nothing stopping you ng new-ing a module based project. The reason why angular is moving towards standalone is because standalone applications are generally simpler to reason about. A component directly imports what it needs. But NgModule are still fully supported with interoperability with standalone components. – Andrew Allen Commented Nov 9, 2023 at 16:37
  • 4 Actually, docs looks wrong, ng new --standalone=false to keep NgModule. Similar for ng generate --standalone=false commands – Andrew Allen Commented Nov 9, 2023 at 16:45
  • 1 create a new project angular 17 with app module "ng new test --no-standalone – JAVED AHMAD Commented Jan 10, 2024 at 11:22
Add a comment  | 

4 Answers 4

Reset to default 186

From Angular v17 onwards, Standalone is now the new default for the CLI.

So when you create a new project, you won't have any modules in it if you don't specify anything.

However, it is still possible to create a module-based app by using the --no-standalone flag :

ng new --no-standalone

Standalone components are a feature introduced in v14. With the change in v17, the Angular team strongly recommends to use them as they are easier to use, understand and are require less boilerplate.

For tutorials using standalone components, I advise you to get a look at the new documentation site.

You can create it manually in the Existing project.

If your Angular project is missing the app.module.ts file, you can create it manually in the src/app directory. Here's a step-by-step guide to create and configure the app.module.ts file in your existing Angular project:

Create app.module.ts File: In your project's src/app directory, create a new file named app.module.ts. Import Required Modules: Open the app.module.ts file and import the necessary Angular modules and Angular Material modules. For example, you might import modules like BrowserModule, FormsModule, ReactiveFormsModule, and Angular Material modules like MatFormFieldModule, MatInputModule, etc.

Here's an example of how the imports section might look:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    ReactiveFormsModule,
    BrowserAnimationsModule,
    MatFormFieldModule,
    MatInputModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

create a new project by running this cmd : ng new projectName --no-standalone

this whould create the app.module.ts

Please use this command it worked for me. It will create a new project.

ng new projectname/file name --no-standalone

example

ng new prjAngular --no-standalone

With this command, it will generate app.module.ts file in src\app.VS folder path The content of above file

本文标签: javascriptWhy doesn39t App Module exist in Angular 17Stack Overflow