Skip to content
  • Github
  • Facebook
  • twitter
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions
  • Site Map

XpertPhp

Expertphp Is The Best Tutorial For Beginners

  • Home
  • Javascript
    • Jquery
    • React JS
    • Angularjs
    • Angular
    • Nodejs
  • Codeigniter
  • Laravel
  • Contact Us
  • About Us
  • Live Demos
Angular 11 Http Get Example Tutorial

Angular 11 Http Get Example Tutorial

Posted on December 30, 2020December 15, 2022 By XpertPhp

In this article, we will know you about the Angular 11 Http Get Example(angular httpclient example). We will give you a simple example of front-end applications that connect to back-end services through the HTTP protocol. so here we will use the HttpClient API provided by Angular CLI.

The HttpClient Service used to send API requests to another server. so we are used to sending data and get data from the server. in this example, we are getting all student data by using HttpClient Service. so you can see our Angular 11 Http Get Example Tutorial.

Read Also: Angular 11 Router Tutorial With Example

Create new angular app

We will create a new angular app using the following command.

1
2
ng new myNewApp
cd myNewApp

when you create your application at that time Angular CLI asks you Would you like to add Angular routing? (y/N). If you enter with y for Yes. then the angular router will be automatically configured.

Creating angular app services

now, we will create the student app services using the following command. it is used to get the data from the backend by calling the rest API. it is used to get the data from the backend by calling rest API. so we need to rest API and you can use any type of created rest API.

1
ng generate service student/student

src/app/student/student.service.ts

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { Injectable } from '@angular/core';
import { HttpClient,HttpHeaders } from '@angular/common/http';
 
@Injectable({
  providedIn: 'root'
})
export class StudentService {
 
  constructor(private httpClient: HttpClient) { }
  baseUrl: string = 'http://localhost/codeigniter4_rest_api/student';
 
  
  getStudents(){
    return this.httpClient.get(this.baseUrl);
  }
}

Use service in component angular

src/app/app.component.ts

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { Component } from '@angular/core';
import { StudentService } from './student/student.service';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'myNewApp';
  
   students: Student[];
 
  constructor(private studentService: StudentService) { }
 
  ngOnInit(): void {
    this.studentService.getStudents()
      .subscribe( data => {
        this.students = data.result;
      });
  }
}
See also  angular 10 image upload with preview image example

src/app/app.component.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<div class="col-md-6 container">
<table class="table table-striped">
    <thead>
    <tr>
      <th>Id</th>
      <th>FirstName</th>
      <th>LastName</th>
      <th>Address</th>
    </tr>
    </thead>
    <tbody>
    <tr *ngFor="let student of students">
      <td>{{ student.id }}</td>
      <td>{{ student.first_name }}</td>
      <td>{{ student.last_name }}</td>
      <td>{{ student.address }}</td>
    </tr>
    </tbody>
  </table>
</div>

Angular 11 App Module

finally, we will import the module in this file. so you can see the below example.
src/app/app.module.ts

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
 
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
 
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
HttpClientModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Run Angular Application

Now we will run our Angular application using the below command.

1
ng serve

Angular Tags:angular 11

Post navigation

Previous Post: Angular 11 Router Tutorial With Example
Next Post: Laravel 8 Vue JS Fullcalendar Example Tutorial

Latest Posts

  • Laravel 12 Ajax CRUD Example
  • Laravel 12 CRUD Example Tutorial
  • How to Create Dummy Data in Laravel 11
  • Laravel 11 Yajra Datatables Example
  • Laravel 11 Ajax CRUD Example
  • Laravel 11 CRUD Example Tutorial
  • Laravel 10 Ajax CRUD Example Tutorial
  • Laravel 10 CRUD Example Tutorial
  • How to disable button in React js
  • JavaScript Interview Questions and Answers

Tools

  • Compound Interest Calculator
  • Hex to RGB Color Converter
  • Pinterest Video Downloader
  • Birthday Calculator
  • Convert JSON to PHP Array Online
  • JavaScript Minifier
  • CSS Beautifier
  • CSS Minifier
  • JSON Beautifier
  • JSON Minifier

Categories

  • Ajax
  • Angular
  • Angularjs
  • Bootstrap
  • Codeigniter
  • Css
  • Htaccess
  • Interview
  • Javascript
  • Jquery
  • Laravel
  • MongoDB
  • MySql
  • Nodejs
  • Php
  • React JS
  • Shopify Api
  • Ubuntu

Tags

angular 10 tutorial angular 11 ci tutorial codeigniter 4 image upload Codeigniter 4 Tutorial codeigniter tutorial CodeIgniter tutorial for beginners codeigniter with mysql crud operation eloquent relationships file upload File Validation form validation Image Upload jQuery Ajax Form Handling jquery tutorial laravel 6 Laravel 6 Eloquent Laravel 6 Model laravel 6 relationship laravel 6 relationship eloquent Laravel 6 Routing laravel 7 Laravel 7 Eloquent laravel 7 routing laravel 7 tutorial Laravel 8 laravel 8 example laravel 8 tutorial laravel 9 example laravel 9 tutorial Laravel Framework laravel from scratch laravel social login learn jquery nodejs pagination payment gateway php with mysql react js example react js tutorial send mail validation wysiwyg editor wysiwyg html editor

Copyright © 2018 - 2025,

All Rights Reserved Powered by XpertPhp.com