Tagged: angular 6 services

Angular 6 Form Validation Example Tutorial 0

Angular 6 Form Validation Example Tutorial

Today, We want to share with you Angular 6 Form Validation Example Tutorial.In this post we will show you Angular 6 – Reactive Forms Validation Example, hear for Angular 6 – Template-Driven Forms Validation Example we will give you demo and example for implement.In this post, we will learn about Angular 6 Validation Tutorial Example From Scratch with an example.

Angular 6 Form Validation Example Tutorial

There are the Following The simple About Angular 6 Form Validation Example Tutorial Full Information With Example and source code.

As I will cover this Post with live Working example to develop Angularjs 6 Form Validation Example Tutorial, so the some major files and Directory structures for this example is following below.

Angular Form Validation Tutorial

app
--app.component.html
--app.component.ts
--app.module.ts
-index.html
-main.ts
-polyfills.ts

Angular 6 Reactive Form Validation

Angular 6 Reactive Form Validation

Angular 6 Example

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

Step 1 : Angular 6 Reactive forms

index.html

<!DOCTYPE html>
<html>
<head>
    <base href="/" />
    <title>Angular 6 Form Validation Example Tutorial</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Include bootstrap css -->
    <link href="//netdna.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
    <app>Loading...</app>
</body>
</html>

Step 2 : Template-driven Angular 6 forms

main.ts

import './polyfills';

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
platformBrowserDynamic().bootstrapModule(AppModule);

Step 3 : polyfills in Angular 6

/polyfills.ts

import 'core-js/es6/reflect';
import 'core-js/es7/reflect';
import 'zone.js/dist/zone';

Step 4 : Angular 6 Create a form with Validation

/app/app.component.html

<!-- Angular 6 with Laravel main app container -->
<div class="pakainfo jumbotron">
    <div class="pakainfo container">
        <div class="pakainfo row">
            <div class="pakainfo col-md-6 offset-md-3">
                <h3>Angular 6 Reactive Form Validation</h3>
                <form [formGroup]="membersForm" (ngSubmit)="onSubmit()">
                    <div class="pakainfo form-group">
                        <label>Member Name</label>
                        <input type="text" formControlName="memberfName" class="form-control pakainfo" [ngClass]="{ 'is-invalid': submitted && validfrm.memberfName.errors }" />
                        <div *ngIf="submitted && validfrm.memberfName.errors" class="invalid-feedback">
                            <div *ngIf="validfrm.memberfName.errors.required">Member Name is required</div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label>Member Sir Name</label>
                        <input type="text" formControlName="memberlName" class="form-control pakainfo" [ngClass]="{ 'is-invalid': submitted && validfrm.memberlName.errors }" />
                        <div *ngIf="submitted && validfrm.memberlName.errors" class="invalid-feedback">
                            <div *ngIf="validfrm.memberlName.errors.required">Member Sir Name is required</div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label>Email</label>
                        <input type="text" formControlName="email" class="form-control pakainfo" [ngClass]="{ 'is-invalid': submitted && validfrm.email.errors }" />
                        <div *ngIf="submitted && validfrm.email.errors" class="invalid-feedback">
                            <div *ngIf="validfrm.email.errors.required">member Email is required</div>
                            <div *ngIf="validfrm.email.errors.email">member Email must be a valid email address</div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label>Password</label>
                        <input type="password" formControlName="password" class="form-control pakainfo" [ngClass]="{ 'is-invalid': submitted && validfrm.password.errors }" />
                        <div *ngIf="submitted && validfrm.password.errors" class="invalid-feedback">
                            <div *ngIf="validfrm.password.errors.required">Password is required</div>
                            <div *ngIf="validfrm.password.errors.minlength">Password must be at least 6 characters</div>
                        </div>
                    </div>
                    <div class="form-group">
                        <button class="btn btn-primary">Signup</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<h2><a href="https://stackblitz.com/edit/angular-6-reactive-form-validation" target="_blank" alt="Angular 6 simple Form Validation Example Tutorial" title="Angular 6 simple Form Validation Example Tutorial">Angular 6 simple Form Validation Demo</a></h2>
<!-- credits -->
<div class="text-center">
    <p>
        <a href="https://pakainfo.com/angular-6-form-validation-tutorial/" target="_top">Angular 6 - Reactive Forms Validation Example</a>
    </p>
    <p>
        <a href="https://pakainfo.com" target="_top">pakainfo.com</a>
    </p>
</div>

Step 5 : Import FormGroup and FormControl in Angular 6

/app/app.component.ts

import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';

@Component({
    selector: 'app',
    templateUrl: 'app.component.html'
})

export class AppComponent implements OnInit {
    membersForm: FormGroup;
    submitted = false;

    constructor(private formBuilder: FormBuilder) { }

    ngOnInit() {
        this.membersForm = this.formBuilder.group({
            memberfName: ['', Validators.required],
            memberlName: ['', Validators.required],
            email: ['', [Validators.required, Validators.email]],
            password: ['', [Validators.required, Validators.minLength(6)]]
        });
    }

    // convenience getter for easy access to form fields
    get validfrm() { return this.membersForm.controls; }

    onSubmit() {
        this.submitted = true;

        // stop here if form is invalid
        if (this.membersForm.invalid) {
            return;
        }

        alert('SUCCESS!! :-)\n\n' + JSON.stringify(this.membersForm.value))
    }
}

Step 6 : Import ReactiveFormsModule in Angular 6

/app/app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ReactiveFormsModule } from '@angular/forms';

import { AppComponent } from './app.component';

@NgModule({
  imports: [
    BrowserModule,
    ReactiveFormsModule
  ],
  declarations: [
    AppComponent
  ],
  bootstrap: [AppComponent]
})

export class AppModule { }

Angular 6 simple Form Validation Demo

Read :

Angular 6 CRUD Operations Application Tutorials

Summary

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

I hope you get an idea about Angular 6 Form Validation Example Tutorial.
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.

Angular 6 Class Binding Tutorial with Examples 0

Angular 6 Class Binding Tutorial with Examples

Today, We want to share with you Angular 6 Class Binding Tutorial with Examples.
In this post we will show you Class Binding & NgClass in Angular 6, hear for Class and Style Bindings in Angular 6 we will give you demo and example for implement.
In this post, we will learn about CSS Class Binding In Angular 6 with an example.

Angular 6 Example

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

Angular 6 Example

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

It would be Best to More Easy Step by step indicate which all the comman Header, Footer and Sidebar page a student is find easly currently on in the display Menu on left sidebar, supportd by putting a dynamic class to the icon chnage that will create This is background blue ore any color? Sure!

So lets start, first of all the go to the /src/app/sidebar/sidebar.component.ts Path file and add the following add the source code:

import { Component, OnInit } from '@angular/core';
import { Router, NavigationEnd } from '@angular/router';

export class SidebarComponent implements OnInit {

  currentUrl: string;
	// default Angular 6 Open File
  constructor(private router: Router) {
    router.events.subscribe((_: NavigationEnd) => this.currentUrl = _.url);
  }

  ngOnInit() {}

}

and then Open the simple file sidebar.component.html This path as well as some source code update it to data content match:

<nav>
  <ul>
    <li>
      <a routerLink="" [class.current]="currentUrl == '/'">
        <i class="material-icons">supervised_student_circle</i>
      </a>
    </li>
    <li>
      <a routerLink="teachers" [class.current]="currentUrl == '/teachers'">
        <i class="material-icons">Angular 6 Class Binding</i>
      </a>
    </li>
  </ul>
</nav>

Angular 6 demo with source code Class binding works by dynamic Include CSS binding Like syntax as [class.csspropertyname] to a HTML view side template more expression. This will only put the .current CSS ruleset (It’s defined in main styles.scss) if simple run or execute the currentUrl is equal to either pages/ or /main teachers.

Read :

Summary

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

I hope you get an idea about Angular 6 Classes with NgClass and NgStyle.
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.

Angular 6 HTTP Client Tutorial with Examples 0

Angular 6 HTTP Client Tutorial with Examples

Today, We want to share with you Angular 6 HTTP Client Tutorial with Examples.
In this post we will show you Angular 6 Http Get Example Tutorial From Scratch, hear for The new Angular 6 HttpClient API we will give you demo and example for implement.
In this post, we will learn about Angular 6 Tutorial: Learn Angular By Building Example CRUD with an example.

Angular 6 Example

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

Angular 6 Example

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

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://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 *ngFor="let student of students$">
    <a routerLink="/details/{{student.id}}">{{ student.name }}</a>

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

Read :

Summary

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

I hope you get an idea about Angular 6 services, HTTPClient.
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.

Angular 6 Services Tutorial with Examples 0

Angular 6 Services Tutorial with Examples

Today, We want to share with you Angular 6 Services Tutorial with Examples.
In this post we will show you Angular 6 Services, hear for Angular 6 CRUD Project Setup, Routing, Service we will give you demo and example for implement.
In this post, we will learn about Angular 6 services, HTTPClient with an example.

Angular 6 Example

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

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.

Read :

Summary

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

I hope you get an idea about Angular 6 and its new features.
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.