The Angular CLI (ng new) is a command-line interface through which developers can quickly create and get Angular applications. Furthermore, it brings about simplicity in the introductory phases of development by generating all necessary files and folder structures that are required for an Angular project to exist.
Why use 'ng new'?
The use of 'ng new' provides several benefits:
- Standardized Structure: Just with the command 'ng new' it creates a well-structured angular application with all the required files and folders.
- Quick Setup: The setup process is very fast as it sets up essential tools like; TypeScript and testing frameworks very speedily.
- Efficiency: It removes the need for manual setup, allowing developers to directly jump into the actual development of their application.
This command serves as an important step for getting started on any new Angular project since it covers several common setups thus simplifying the whole process of starting with Angular programming.
Prerequisites
Approach
Basic Project Setup ('ng new project name')
This is the default way of generating a new Angular project. It creates the necessary file structure and includes everything required to start development.
ng new project-name
Customize the Setup
The --routing flag will cause an additional app.routes.ts file to be created, which is used for establishing an application's routes in Angular. This means that it is ideal if you wish to have navigation across your application.
Specifying a Style Language (--style=<style>)
The --style option lets one to select a desired style sheet language like CSS, SCSS or LESS. This is very important if an individual project needs certain form of styling.
Skipping Unnecessary Files (--skip-tests)
Developers who want to create a project without generating test files should opt for the --skip-tests option. This is helpful for developers who prefer creating tests at later stages or when testing does not serve as the focal point of the project.
Use Strict Mode (--strict)
The --strict flag enables strict type checking and more rigorous rules in the TypeScript compiler. This suits projects that would like code with higher quality and better type safety.
When creating a new Angular project using the 'ng new' command, there are a few different options you can pass to customize the setup:
Basic Syntax:
ng new <project-name>
Additional Options and Flags:
- '--routing': Adds a 'routing' module to your project.
- '--style=<style>': It specifies the styling language to be used for example: (CSS,SCSS,LESS),
- '--skip-tests': It is used to skip the test file creations.
- '--strict': It enables strict type checking and more strict rules.
Example:
ng new my-angular-app --routing --style=scss --skip-tests --strict
Steps to Create Application (Install Required Modules)
Let's see how to create an Angular application using the 'ng new' command step-by-step:
Step 1: Install Angular CLI
If you haven't already installed Angular CLI, install it by using the command:
npm install -g @angular/cli
Step 2: Create a new Angular Project
ng new my-angular-app
ng new my-angular-app --routing --style=scss --skip-tests --strict
The above command will create an Angular project with the name 'my-angular-app' with routing enabled, SCSS for styling, test files skipped and strict type checking.
Step 3: Navigate to Project Directory
After the project is created, move into the project directory:
cd my-angular-app
Folder Structure
Folder StructureDependencies
"dependencies": {
"@angular/animations": "^18.0.0",
"@angular/common": "^18.0.0",
"@angular/compiler": "^18.0.0",
"@angular/core": "^18.0.0",
"@angular/forms": "^18.0.0",
"@angular/platform-browser": "^18.0.0",
"@angular/platform-browser-dynamic": "^18.0.0",
"@angular/platform-server": "^18.0.0",
"@angular/router": "^18.0.0",
"@angular/ssr": "^18.0.0",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.14.3"
}
Step 4: Start the Development Server
To see your application is in action, start the Angular development server by using the following command:
ng serve
Your application will be available at 'http://localhost:4200/'.
Output
Similar Reads
Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
JavaScript Tutorial JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side: On the client side, Jav
11 min read
Web Development Web development is the process of creating, building, and maintaining websites and web applications. It involves everything from web design to programming and database management. Web development is generally divided into three core areas: Frontend Development, Backend Development, and Full Stack De
5 min read
Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
React Interview Questions and Answers React is an efficient, flexible, and open-source JavaScript library that allows developers to create simple, fast, and scalable web applications. Jordan Walke, a software engineer who was working for Facebook, created React. Developers with a JavaScript background can easily develop web applications
15+ min read
React Tutorial React is a powerful JavaScript library for building fast, scalable front-end applications. Created by Facebook, it's known for its component-based structure, single-page applications (SPAs), and virtual DOM,enabling efficient UI updates and a seamless user experience.Note: The latest stable version
7 min read
JavaScript Interview Questions and Answers JavaScript is the most used programming language for developing websites, web servers, mobile applications, and many other platforms. In Both Front-end and Back-end Interviews, JavaScript was asked, and its difficulty depends upon the on your profile and company. Here, we compiled 70+ JS Interview q
15+ min read
Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact
12 min read
Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and
9 min read
3-Phase Inverter An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power
13 min read