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 |4 Answers
Reset to default 186From 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
版权声明:本文标题:javascript - Why doesn't App Module exist in Angular 17? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736912667a1956191.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
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:37ng new --standalone=false
to keep NgModule. Similar forng generate --standalone=false
commands – Andrew Allen Commented Nov 9, 2023 at 16:45