ANGULAR ng new
ANGULAR
The ng new command is used to create a new project in Angular.
Angular ng new command
➔ Angular uses this command ng new project-name to create a new project in Angular.
➔ With the ng new command, developers can quickly create and get the default project structure.
➔ This project is built with a basic structure that contains all the necessary files and a standard folder structure.
➔ The ng new command creates projects very efficiently and without any manual configuration or setup files.
➔ This is an important setup for beginners where project development can be started using just one command. This simplifies the process of getting started with Angular programming.
➔ Project creation and setup can be customized using optional flags along with basic commands. In that case, additional features are included.
The most commonly used flags are
--routing: Includes the routing module in the project.
--style: This flag specifies which styling language will be used in the project.
--skip-test: Tells Angular not to manage test-related libraries and tools when creating the project. Testing functionality can be added later if needed.
--strict: This specifies that Angular will strictly follow type checking.
Other commonly used flags are
--standalone: This specifies that the new project will be built using standalone components, directives, and pipes instead of the ngModule-based structure. Modern Angular versions use this option by default.
--inline-style: This specifies that the component will have inline styles in the TypeScript file, instead of a separate style file.
--inline-template: This specifies that the component will have an inline HTML template in the TypeScript file, instead of creating a separate HTML file.
--dry-run: This tells angular that the file will be created without actually creating it on disk.
Syntax of ng new
# Create a new project with SCSS styling, routing, and strict mode enabled.
ng new my-angular-app --style=scss --routing --strict
# Create a project with inline styles, inline templates and no tests.
ng new my-app-inline -s -t --skip-tests
Flags and alias
| Options | Alias | Description |
|---|---|---|
| --inline-style | -s | Creates inline style. |
| --inline-template | -t | Inline template will be used, instead of creating separate HTML file. |
| --minimal | Create a bare-bones compact project without any testing supports. | |
| --prefix | -p | A prefix applied to selectors. |
| --routing | Create a routing NgModule for the application. | |
| --skip-install | dependency packages should not be installed. | |
| --skip-package-json | Tells not to dependencies to "package.json" file. | |
| --skip-tests | -S | The "spec.ts" test file should not be created. |
| --strict | Creates an application with strict mode settings. | |
| --style | The file extension to use for style files. |