Archive for the ‘Angular 2’ Category

Angular 2: Adding bootstrap css framework

In my previous post I showed you how to create an Angular 2 application using angular-cli tool. This post is a continuation of that and in this post I am going to show how to use node package manager npm to add bootstrap stylesheet and wire it up in the application.

I am going to open the nodejs command prompt and install the bootstrap css package to the project using the following command.

C:\>npm install ng2-boostrap –save


If you browse to the node_modules folder you can see the new folder bootstrap was created which contains all the stylesheets as shown below.

Bootstrap CSS added to the angular 2 project

In order to make the stylesheet available for the page we have to add the path of the file to the styles array which is defined in the .angular-cli.json file. Since it is an array you can add multiple stylesheets and the loader will take care of it.


"styles": [

adding css location to the styles array

Now I am going to add some menu with the search text box and a jumbroton layout to give it a nice look.

  <nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <div class="navbar-header">
      <a class="navbar-brand" href="#">NG Corporationa>
    <ul class="nav navbar-nav">
      <li class="active"><a href="#">Homea>li>
      <li><a href="#">Abouta>li>
      <li><a href="#">Servicea>li>
      <li><a href="#">Contacta>li>
    <form class="navbar-form navbar-right">
      <div class="input-group">
        <input type="text" class="form-control" placeholder="Search">
        <div class="input-group-btn">
          <button class="btn btn-default" type="submit">
            <i class="glyphicon glyphicon-search">i>
  <div class="container">
    <div class="row">
      <div class="jumbotron">
        <h1>NG Corporationh1>      
        <p>A place to use your creativity, innovation and passion to build exciting product for the world.p>

As you can see pretty standard bootstrap template and at the end we have our angular component with the custom selector “app-root”. Last thing we have to do is to run the following command in order to start the application.

C:\>ng serve

And here is the angular 2 application up and running with bootstrap styling.

bootstrap style applied to the website

Getting started with Angular CLI

March 19, 2017 3 comments

In this post I am going to show you how to install angular-cli and create a new Angular 2 application. It will be very useful if you are familiar with NodeJS, Node Package Manager(npm), TypeScript and Visual Studio Code (VSCode).

Lets get started with downloading NodeJs from

download node from

There are plenty of operating system to choose and since I am on Windows 10 64-bit, I am going to use the Windows Installer(.msi) 64-bit. This will install the nodejs runtime. Search and open the nodejs command prompt and install the angular-cli package using npm.

npm install -g @angular/cli

npm install angular-cli

If you are using a proxy server then you might have to set the "https-proxy " value in the npm configuration as shown below.

npm config set https-proxy

and after a while you will see that the angular-cli installation was successful.
angular-cli installation completed

Lets check the version of the angular-cli by using the following command.

ng -v

verify angular-cli version

As you see I am using nodejs version 6.9.2 and angular-cli is in rc1 although the current version is rc2 which has been released a couple of days ago.

So after all the required installation I’m now going to create a new application helloworld using the angular-cli.

ng new helloworld

ng new to create a new application

and you will see that the angular-cli has created a bunch of folders and files under the helloworld folder.

view the application folder structure

In order to run the application I’m going to use the ng serve command to run the application.

run the application

By default the application runs on port 4200 so lets browse to http://localhost:4200 and you can see the application is up and running and you can change the default port to any port by specifying the –p parameter to the ng serve command.

browse to the application

Lets open the project root folder using Visual Studio Code and modify the app.component.ts (TypeScript) file.

open the solution in visual studio code

As soon as I change the title property of the AppComponent to "Hello world from Angular 2" the page automatically refreshes and shows my changes, I don’t have to hit F5 or refresh the page at all.

page automatically refreshes

Congratulations you just created your first Angular 2 application using angular-cli.