angular 6 tutorial for beginners step by step

Today, We want to share with you Angular 6 Tutorial with Examples.
In this post we will show you Angular 6 Tutorial Step By step, hear for Angular 6 – User Registration and Login Example & Tutorial we will give you demo and example for implement.
In this post, we will learn about Angular 6 Tutorial With Example using Angular CLI with an example.

angular 6 tutorial for beginners step by step

angular 6 tutorial
angular 6 tutorial

Angular Latest My Previous Post With Source code Read more…..

  1. Angular 6 Folder Project Structure
  2. Angular 6 CLI Installation
  3. Angular 6 Module File
  4. Angular 6 Components
  5. Angular 6 Services
  6. Angular 6 Routing
  7. Angular 6 CSS
  8. Angular 6 Class Binding
  9. Angular 6 Animation
  10. Angular 6 Templating
  11. Angular 6 HTTP Client

First of all Simple We know to Need Angular Basic Version Such as AngularJS , Angular 2, Angular 4 and Angular 6.

Angular 6 Features Architecture Overview

There are the Following the list of the Angular 6 Additions & New Features

  • Angular Material changelog
  • Full changelog
  • RxJS 6 at ngConf
  • RxJS 6 migration guide
  • add a ng add
  • add a ng update
  • add a ngConf

And the More Details of the Angular 6 Features Below link.

Angular 6 Additions & New Features

And then Angular 6 next step To Basic Learn To Angular 6 Folder Project Structure

Angular 6 Simple Project Structure

    src
    app
    _directives
    _guards
    _helpers
    _models
    _services
    home
    login
    register

an Angular is a smart platform as well as client sbased framework for building web applications in HTML source cpde as well as more TypeScript. example of the Angular is written in simple based on a TypeScript. It implements core JavaScript as well as optional more added functionality as a set of TypeScript some imp libraries that you import into your web single page application.

Angular 6 CRUD – Part 1: Project Setup, Routing, Service

We will follow below mentioned steps.

  • first of all the Angular 6 latest package Development Environment
  • and then Install Bootstrap latest version 4 in an Angular 6 application
  • setting angular 6 Routing and navbar for components js
  • create a dummy JSON server side that save the data.
  • config HttpClient for angular server side service.

Step 1: Angular 6 Development basic Environment

and Then install the Angular 6 CLI globally.

npm install -g @angular/cli
ng new student-app
cd student-app
ng serve –open

Step 2: Install Bootstrap 4 Angular 6.

I will be using Bootstrap for styles in Simple 6 application. Therefor, install latest version 4 Bootstrap by executing the following some CMD to run command from the command prompt.

angular.json

"styles": [
               "./node_modules/bootstrap/dist/css/bootstrap.min.css",
              {
                "input": "src/styles.css"
              }
            ],

Step 3: Configure Routing and navigation for components.

And then, make a angular 6 component to view the list of products. Name it ListProductsComponent.

ng g c products/listProducts --spec false --flat true
ng g c products/createProduct --spec false --flat true

And then I have to scripts whole source code inside like as app.module.ts file.

app.module.ts

// app.module.ts 
 
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { ListProductsComponent } from './products/list-products.component';
import { CreateProductComponent } from './products/create-student.component';
 // Import RouterModule
import { RouterModule,Routes } from '@angular/router';
 
 
 const appRoutes: Routes = [
  { path: 'list', component: ListProductsComponent },
  { path: 'create', component: CreateProductComponent },
  { path: '', redirectTo: '/list', pathMatch: 'full' }
];
 
 
@NgModule({
  declarations: [
    AppComponent,
    ListProductsComponent,
    CreateProductComponent
  ],
  imports: [
    BrowserModule,HttpClientModule,
    RouterModule.forRoot(appRoutes)
  ],
  providers: [ProductService],
  bootstrap: [AppComponent]
})
export class AppModule { }

app.component.html file

// app.component.html 
<div class="container">
    <nav class="pakainfo navbar navbar-default">
        <ul class="nav navbar-nav">
            <li> <a routerlink="list">Product List</a> </li>
            <li> <a routerlink="create">Add Product</a> </li>
        </ul>
    </nav>
    <router-outlet></router-outlet>
</div>

The Angular 6 Module File

Before we angular 6 some Post components, Angular worth looking at the Angular 6 Module File -> /src/app/app.module.ts file. So, As well as by the way, what is Angular 6 Module .ts extension? It stands for any latest version Angular TypeScript, as well as Angular 6 uses TypeScript. In short, TypeScript supported strong Data type checking on pure JavaScript.

The Angular 6 Module File -> app.module.ts file looks like source code:

//import angular 6 some TypeScript files
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

//import angular 6 some TypeScript files
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

//angular 6 NgModule
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule   //Angular 6 Module routing File
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Whenever you use the CLI to generate components and services, it will dynemically automatically update this folder add and update file to import and put them to the new angular 6 futers @NgModule decorator. and then angular 6 Components are added to the varibles globaly declarations array, and angular 6 services are puted as some providers. You will also search yourself adding various imports to the imports array. For angular instance, when I want to put animations, I will put them here.

If We are a some data angular/core confused at this section, don’t worry. step by step understand and then this is best way to Good component an important folder and file that We will should to display routinely and URL bind. The angular CLI will step by step angular 6 of things for the most part, Data bind and especially when generating components, so when Data binding and generating angular/core services as well as performing some more generated tasks, you will should to display this Angular file. We shall display view as a some proceed.

Angular 6 Components Tutorial With Examples

The Angular 6 CLI to generate some components

//Angular 6 Components Tutorial
-> src
	-> app
		app.component.html
		app.component.scss (or .css)
		app.component.spec.ts
		app.component.ts

Open up the app.component.ts file:

// file name : app.component.ts
import { Component } from '@angular/core';

//Angular 6 Components
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})

export class AppComponent {
  title = 'pakainfo';
}

The angular 6 @Component decorator is one types of the an object with associated some property / value both pairs that Innformatic declare required data stuff associated types with angular 6 component.

In the console, run: for Angular CLI

//generated Angular 6 Components Examples
> ng generate component sidebar
CREATE src/app/sidebar/sidebar.component.html (28 bytes)
CREATE src/app/sidebar/sidebar.component.spec.ts (638 bytes)
CREATE src/app/sidebar/sidebar.component.ts (278 bytes)
CREATE src/app/sidebar/sidebar.component.scss (0 bytes)
UPDATE src/app/app.module.ts (477 bytes)

Let’s start Good Prectice for New generate a few more Angular 6 components

> ng g c articles
> ng g c emploess
> ng g c informationsclients

Angular 6 Components Basic, We shall display step by step how all of main first these start to work for angular project with each other app’s and in relation Components to the app.

Angular 6 Services Tutorial With Examples

For our simple clients component, we want to fetch a list of clients from a public API. To do that, I am gonna to use the simple Main Angular CLI to created CMD to Run a service for us.

An Angular 6 service is Most useful placing source code More time reusable So Our’s web app’s use the manin sidebar menu, footer, Header different Angular 6 components.

Run this Commands for Console:

> ng generate service data

and the simple Open To the new created service file: such as /src/app/data.service.ts:

//Import Angular 6 service
import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
//export service
export class DataService {

  constructor() { }
}

It looks similar angular/core to a regular HTML Angular 6 template component, right? We can define all the your imports at the namespaces and external Libs on the top, and We some useful methods and functions with some properties in the some custom Js and CSS class that’s included.

The useful Post of our angular 6 service file data will be to save and component and modules communicate with webservices an API via the GET and POST Methods Angular 6 HTTP Client to server Side.

Angular 6 Routing Tutorial With Examples

/src/app/app-routing.module.ts

Add the following Angular 6 Routing: We can add config file or global angular 6 custom Routing to this add file, and also more import change other Routing custom files

/* Angular 6 Routing Example */
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

//global valuable
const routes: Routes = [];

//change angular 6
@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

And then, second We should to import angular source code our more components at the simple top, and put them to the angular 6 Routes array displayed on line next above. /src/app/app-routing.module.ts for Angular 6 Routing

/* Angular 6 Routing Example */
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { ClientComponent } from './users/users.component';
import { StudentComponent } from './student/student.component';
import { SubjectComponent } from './subjects/subjects.component';

//change angular 6
const routes: Routes = [
  {
    path: '',
    component: ClientComponent
  },
  {
    path: 'student/:id',
    component: StudentComponent
  },
  {
    path: 'subjects',
    component: SubjectComponent
  },
];

The first of all this 1 object particuler that the angular 6 ClientComponent will be the main root or default component run that all the templates loads on the root main path. I leave the simple display data path value empty for this components.

Angular 6 CSS Tutorial With Examples

/src/styles.css

Add the following Angular 6 CSS: We can add config file or global angular 6 custom styles to this add file, and also more import change other css style files

/* Angular 6 CSS Example */
body {
     margin: 0;
     background: #ccc;
     font-family: 'Montserrat', sans-serif;
     height: 100vh;
}

#container {
    display: grid;
    grid-template-columns: 70px auto;
    height: 100%;

    #content {
        padding: 25px 45px;

        ul {
            list-style-type: none;
            margin:0;padding:0;
        
            li {
                background: #ffffff;
                border-radius: 8px;
                padding: 20px;
                margin-bottom: 8px;
        
                a {
                    font-size: 1.5em;
                    text-decoration: none;
                    font-weight: bold;
                    color:#3d3d3d;
                }
        
                ul {
                    margin-top: 15px;
                    
                    li {
                        padding:0;
        
                        a {
                            font-size: 1em;
                            font-weight: 600;
                        }
                    }
                }
            }
        }
    }
}

And then, second open up the simple sidebar widgets CSS file Like as a /src/app/sidebar/sidebar.component.scss for Angular 6 CSS

nav {
    background: #3d3d3d;
    height: 100%;

    ul {
        list-style-type: none;
        padding: 0;
        margin: 0;

        li {

            a {
                color: #ffffff;
                padding: 25px;
                display: block;
            }

            .activated {
                background-color: #c60000;
            }
        }
    }
    
}

Angular 6 Animation Tutorial With Examples

In order to gain retrive to An Angular 6 animation main library, I have to first of all Angular 6 CLI install it from the console:

> npm install @angular/[email protected] --save

After That, I pur it to the simple File Path imports of such /src/app/app.module.ts:

// Other angular 6 imports deleted for brevity
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

@NgModule({
  ...
  imports: [
    //angular 6 other modules deleted for some brevity
    BrowserAnimationsModule
  ],
})

After that, open This path sucha as /src/app/clients/clients.component.ts and then here put the following some source code to the top main part imports:

Angular 6 Animation Syntx:

import { trigger,CSSstyle,Timetransition,animate,somekeyframes,generatedquery,stagger } from '@angular/animations';

and then, in the angular 6 component console decorator, put the source code following angular 6 animations some useful property with the attribuets and more params associated source code:

@Component({
  selector: 'app-clients',
  templateUrl: './clients.component.html',
  styleUrls: ['./clients.component.scss'],

  //angular 6 Add this:
  animations: [
    trigger('packageEmployes', [
      transition('* <=> *', [
        query(
          ':enter',
          [
            style({ opacity: 0, transform: 'translateY(-15px)' }),
            stagger(
              '60ms',
              animate(
                '560ms ease-out',
                style({ opacity: 1, transform: 'translateY(0px)' })
              )
            )
          ],
          { optional: true }
        ),
        query(':leave', animate('60ms', style({ opacity: 0 })), {
          optional: true
        })
      ])
    ])
  ]
})

To create That work, Go and open the /src/app/clients/clients.component.html file and reference the animation click Push trigger:

<ul [@packageEmployes]="clients$">

Save it, and thenclick on the clients icon. We Shall required that the list angular 6 animates in!

Angular 6 Templating Tutorial With Examples

first of all simple Open the this path and file src/app/app.component.html file. We shall display all of the angular typescripts boilerplate main DOM HTML the CLI way to cmd run and generated, and consequently, what We display in the defult browser for the some time being. Delete all of that and paste this:

<div id="container">
  <app-sidebar></app-sidebar>

  <div id="content">
    <router-outlet></router-outlet>
  </div>
</div>

Sidebar Angular 6 Templating

The simple path Like as a /src/app/sidebar/sidebar.component.html file.

<nav>
  <ul>
    <li>
      <a routerLink="home">
        <i class="material-icons">Homt</i>
      </a>
    </li>
    <li>
        <a routerLink="articles">
          <i class="material-icons">Articles</i>
        </a>
      </li>
  </ul>
</nav>

and then Save this ctrl + s file and open simple path Like up /src/index.html and then put the following 2 lines source code between the HTML tags:

<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
      rel="stylesheet">

<link href="https://fonts.googleapis.com/css?family=Montserrat:300,700" rel="stylesheet">

Angular 6 HTTP Client Tutorial With Examples

Angular Starts with a main built Data Type with Methods Data send in HTTPClient. So We started import all the libs that at the top of simple data.service.ts file:

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

And then, in some order to use the browser client side request HttpClient, I should to make basic an instance of it although more dependency and best injection within the angular/common/http constructor:

 constructor(private http: HttpClient) { }

  getStudents() {
    return this.http.get('https://www.pakainfo.com/students')
  }

We also some uniq Angular 6 defined a method called as a getStudents() which I shall call in angular 6 component shortly. This is returns a all the list of students from a public information testing API.

Also I can use the angular 6 HTTPClient, I shortly need to put as some an import in our angular application /src/app/app.module.ts file:

// angular 6 Other imports students removed for brevity

import { HttpClientModule } from '@angular/common/http';  // <-students Put here

@NgModule({
  declarations: [
    // here source code students Removed for brevity
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    HttpClientModule,  // <-students Put here
  ],
  providers: [],
  bootstrap: [AppComponent]
})

And then, simple this path open up such as the /src/app/students/students.component.ts file and import our source code for service:

import { Component, OnInit } from '@angular/core';
import { DataService } from '../data.service';
import { Observable } from 'rxjs';

In the Dynamicclass, Put:

export class StudentsComponent implements OnInit {

  students$: Object;
  
  constructor(private data: DataService) { }

  ngOnInit() {
    this.data.getStudents().subscribe(
      data => this.students$ = data 
    );
  }

}

After That, open simple this file path up /src/app/students/students.component.html:

<h1>Students</h1>

<ul>
  <li>
    <a>{{ student.name }}</a>

    <ul>
      <li>{{ student.email }}</li>
      <li><a href="http://{{ student.website }}">{{ student.website }}</a></li>
    </ul>
  </li>
</ul>

Angular 6 CLI Installation Tutorial With Example

The How to Install Angular 6 Tutorialquickest and easiest way step by step of starting an Angular 6 Setup, Install, & Build Guide is through The Angular CLI

.

Install Angular 6, We are going to should either the yarn package manager or the node package manager. To check whether or not We have npm, in your CMD console / command line, type:

> npm -v

And then, we can use simply Node Install NPM to install The Angular CLI – https://cli.angular.io/. The Angular CLI has an official website click this link to located Angular CLI.

> npm install -g @angular/cli

If We run simply CMD to run this ng -v and then installing, it will supported We with the npm version number. Like as happens to be npm version 6.0.7.

And then the Angular CLI is successfully installed, we can simply now use it to angular CLI start a install a new make Project brand new Angular 6 step by step:

> ng new ng6-proj --style=scss --routing

ng – call the Angular CLI.

new – many some run commands we can issue to the Angular 6 CLI.

ng6-proj is project Name. The CLI will make a folder with and project name

Optional params – And then are two some arguments optional params that I decided to puted. First, we’re telling the CLI to generate a project that has Sass enabled, and then angular 6 –routing is puted because we want a create project that has different module and angular 6 componets page URL’s, and putting this params will help make a angular 6 different routing file for us.

To check all the source code related sticky books out all of the CMD run command available commands and more default options, simple run ng at the angular 6 project command line.

Once The Angular CLI – https://cli.angular.io/ has generated the new project, We can hop into it:

> cd ng6-proj

If We use The Angular CLI – https://cli.angular.io/ Visual Studio source Code, We can type code Angular 6 – Setup for local development. to launch the source code editor. Then, to save serve the project or angular 6 web application to the any setup default browser, We this cmd to run:

> ng serve -o

And the More Details of the Angular 6 Features Below link.

Angular 6 Folder Project Structure

More Details of the Angular 6 Angular 6 Introduction Tutorial features of angular 6.0

Angular 6 Examples

There are the Angular 6 Step By Step Example and Learning AngularJS

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Angular 6 Overview With Examples.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1.   PHP Multiple Checkbox Array Handling Tutorial Example
  2.   AngularJS Modules Tutorial with Example
  3.   Curl GET And POST Method Calls – PHP Example
  4.   Codeigniter Create custom library
  5.   Simple Hello World Example using Angular
  6.   Angular 6 Expressions Tutorial with Examples
  7.   Get maximum key value of array in PHP
  8.   Top 10 Angular2 Interview Questions and Answers
  9.   Autocomplete Textbox using jQuery, PHP and MySQLi
  10.   Extract XML Response in PHP Example