The Angular team had announced about Angular CLI tool that makes creating and scaffolding Angular 2 applications incredibly easy in the NG-Conference 2016. Angular CLI is a command line interface for you to work with Angular and also to automate your development workflow. To provide you with the superficial features of the Angular CLI, it makes it easier to work with already created applications right out of the box.
Angular CLI allows you to do the following:
You can create a new Angular application (using command ng new)
You can run a development server to preview your application during development
To build your application for deployment to an environment of your choice
To add additional features to your Angular applications (using command ng generate)
To run your Angular application’s unit tests (using command ng serve)
To run your Angular application’s end-to-end tests
With these basic features of Angular CLI available to use, you should be looking forward to starting with the setup process. Let’s delay no further and get deep diving into the setup process.
Want To Get AngularJS Training From Experts? Enroll Now For Free Demo On AngularJS Training.
Installing the Angular CLI:
The pre-requisite for us to have before we can use Angular CLI are Node.js (6.9.0) and npm (3.0.0 or higher) installed on your system. You can follow the Official documentation available here and download the latest version of Node.js for your OS and follow the given instructions. If you already have the pre-requisites already available on your system, then it is the right time to check the versions available using the following commands.
$ node –v # (displays the Node.js version installed) $ npm –v # (displays the npm version installed)
With the pre-requisites handled, the next step is to have ‘TypeScript’ installed on your system. It is not at all mandatory to have TypeScript installed along with Node.js, npm – but as a recommendation from the Angular team, it is 100% better to have this on your system. The following command should do the trick, if the pre-requisites are handled correctly.
$ npm install –g firstname.lastname@example.org
With the above pre-requisites and the recommendations handled, now we are at the final step of installing Angular CLI on our system. The following command helps us install the Angular CLI tool on our system:
$ npm install –g @angular/cli
The command above installs, ng command as a global one, which can be verified as shown in the next step below.
$ ng version @angular/cli: 1.2.1 node: 6.9.0 os: darwin x64
With this step done successfully, you are now ready to create new applications. The next section describes the process of creating newer Angular applications.
Creating a new Angular Application:
Creating a new application can be done in two ways, using either of the following commands (using Angular CLI):
ng init – This command creates a new Angular application in the present folder.
ng new – This command creates a new folder and then under the new folder if we run ng init it creates a new Angular application.
Putting the commands above to use, let’s create a new application called ‘my-angular-application’.
$ ng new my-angular-application
The command above does the following in the background and generates the application skeleton for us to develop it further. Let’s strip the above command to bare bones and try to understand each step individually.
Since we’ve used the command ng new, it will create a new folder called my-angular-application.
Source files and folders are created based on the application name that you choose, hence it is very important for every one of us to follow the official Angular style guide.
npm dependencies are all installed if it is the first application that you are creating using the command mentioned above.
TypeScript will be configured
Karma unit test runner will be configured
Protector end-to-end test framework will also be configured
All the necessary environment files are created with the default settings
For more info Check here AngularJs6