Site icon NgDeveloper

5 Basic things to know in angularjs-cli:

5 Basic things to know in angularjs-cli:

 

These are the few basic and must know things before starting with angularjs-cli. Assuming node js is installed already, if no please follow the steps in the below link and get it installed,

 

 

 

1. Command to install angular-cli:

 

npm install -g angular-cli

 

This installs angular-cli globally on your system.

 

2. Command to create angular-cli required files to run your first app

 

ng new Hello

 

This creates the folder named “Hello” and creates the files required to start working with angular-cli.

 

 

3. Command to start angular-cli development server:

 

ng serve

 

ng test

This is the command you can make use to run unit testing.

 

 

4. Default port number for angularjs 2:

 

By default 4200 is the port allocated for angularjs application. You can navigate to the below url once after the successful start of the development server,

http://localhost:4200/

But you can change the port like this

ng serve –port 13123

Now the application will be available in http://localhost:13123/

 

 

5. Command to run Production Build:

ng build –prod

 

ng serve –prod

Basically –prod minimizes the files, but there will not be any change in the output.

 

What is angular-cli.json file ?

angular-cli.json file is a important configuration file in angular-cli project which has the details like project name, angular-cli version, styles and scripts etc..

Note: Even though angular-cli uses live reload server, if you modify angular-cli.json file you need to restart the server to reflect the changes. But if you are making changes in .html, .css/.scss, .ts, .spec.ts not needed to restart the server.

 

 

Apart from the above 5 basic things know below comments as well for better knowledge in angular-cli:

Command to create classes, pipes, directives, components:

Generating components:

ng generate component Hello

 

Generating class:

ng generate class Hello –spec

 

–spec creates unit testing files as well.

 

Generating directive:

ng generate directive Hello

 

Generating pipe:

ng generate pipe Hello

 

Note:

ng generate pipe all_pipes/Hello

 

ng g component javadomain

 

 

 

Few More Commands:

 

To know the version:

ng –version / ng -v

 

By default below command creates the styles file in .css, 

ng new myProject

 

if you want to create .scss file then,

ng new myProject –style=scss

 

 

Things to know in Angular – High Level:

  1. Components
  2. Data Binding
  3. Directives
  4. Pipes
  5. Routing
  6. Http
  7. Observables

 

Understanding Angular-cli Folder structure:

Here,

 

Inside src:

 

 

How to update your angular (like angular core to new versions available) ?

npm uninstall -g angular-cli
npm cache clean
npm install -g @angular/cli@latest

 

we will face the below errors if we upgrade only angular core:

 

So always plan to run the below commands also as part of your upgrade:

npm install @angular/common@latest @angular/compiler@latest @angular/compiler-cli@latest @angular/core@latest @angular/forms@latest @angular/http@latest @angular/platform-browser@latest @angular/platform-browser-dynamic@latest @angular/platform-server@latest @angular/router@latest @angular/animations@latest typescript@latest --save

 

This post is written with the intention to provide you very basic things in more accessible way and as quick as possible. Feel free to share your comments below to add/modify/remove the content of the post.

Exit mobile version