Professional Documents
Culture Documents
INVESTMEN
ANGULAR
6 FORMS
TUTORIA
EXAMPLE
FROM
SCRATCH
ANGULAR
6
ROUTING
EXAMPLE
ANGULAR ANGULAR
6 CRUD
EXAMPLE
TUTORIA
FROM Angular 6 Http Get
SCRATCH
Example
ANGULAR
6 EVENT
MAY 14, 2018 8 MIN READ
BINDING
EXAMPLE
TUTORIA
ANGULAR
COMPON
TUTORIA
WITH
EXAMPLE In this tutorial, we will see Angular
ANGULAR 6 Http Get Example. Most modern
6 front-end applications
LOADING
SPINNER communicate with backend
EXAMPLE services over the HTTP protocol.
ANGULAR They communicate via an API. The
FORM HttpClient in
VALIDATI @angular/common/http o ers a
EXAMPLE
simpli ed client HTTP API for
TUTORIA
Angular applications that rests on
ANGULAR
MATERIA the XMLHttpRequest interface.
DATEPIC
EXAMPLE For this example, we will create a
TUTORIA backend JSON server. Then Angular
https://investmentnovel.com/angular-6-http-get-example/ 1/10
4/15/2020 Angular 6 Http Get Example Tutorial From Scratch
VUE.JS
BOOTSTRA
ANGULAR 6 HTTP GET
LARAVEL EXAMPLE
NODE.JS We install Angular via Angular CLI.
MONGODB
#1: INSTALL ANGULAR
6 PROJECT.
If you have not installed Angular
CLI globally on your machine, then
install it using the following
command.
# or
https://investmentnovel.com/angular-6-http-get-example/ 2/10
4/15/2020 Angular 6 Http Get Example Tutorial From Scratch
Replay
ng new ng6http
ng serve --open
FIND US ON
# or
FACEBOOK
npm install -g json-server
InvestmentNo
41 likes
Like Page
https://investmentnovel.com/angular-6-http-get-example/ 3/10
4/15/2020 Angular 6 Http Get Example Tutorial From Scratch
CATEGORIES
ANGULAR
BOOTSTRAP
Replay
C
LARAVEL
MONGODB
{
"books": [
{
"id": "1",
"name": "A song of ice and fi
"author": "George RR Martin"
},
{
"id": "2",
"name": "Harry Potter",
"author": "JK Rowling"
},
{
"id": "3",
"name": "Anna Karenina",
"author": "Leo Tolstoy"
},
{
"id": "4",
"name": "Great Expectations",
"author": "Charles Dickens"
},
{
"id": "5",
"name": "Middlemarch",
"author": "George Eliot"
}]
}
https://investmentnovel.com/angular-6-http-get-example/ 4/10
4/15/2020 Angular 6 Http Get Example Tutorial From Scratch
#3: SETUP
HTTPCLIENT.
Now, Angular comes with
HttpClient Module, so we just need
to register inside our application.
So open the app.module.ts le and
write the following code.
// app.module.ts
imports: [
BrowserModule,
HttpClientModule
],
https://investmentnovel.com/angular-6-http-get-example/ 5/10
4/15/2020 Angular 6 Http Get Example Tutorial From Scratch
// Book.ts
ng g s book --spec false
https://investmentnovel.com/angular-6-http-get-example/ 6/10
4/15/2020 Angular 6 Http Get Example Tutorial From Scratch
// app.module.ts
providers: [BookService],
// book.service.ts
@Injectable({
providedIn: 'root'
})
export class BookService {
url = 'http://localhost:4000';
constructor(private http: HttpClien
getBooks() {
return this
.http
.get(`${this.url}/books`)
}
}
// app.component.ts
https://investmentnovel.com/angular-6-http-get-example/ 7/10
4/15/2020 Angular 6 Http Get Example Tutorial From Scratch
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app';
books: Book[];
constructor(private bookService: Bo
ngOnInit() {
this
.bookService
.getBooks()
.subscribe((data: Book[]) => {
this.books = data;
});
}
}
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Author</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let book of books">
<td>{{ book.id }}</td>
<td>{{ book.name }}</td>
<td>{{ book.author }}</td>
</tr>
</tbody>
</table>
https://investmentnovel.com/angular-6-http-get-example/ 8/10
4/15/2020 Angular 6 Http Get Example Tutorial From Scratch
GITHUB CODE
Tweet Like 2
Save
ANGULAR ANGULAR 6
RELATED POSTS
ANGULAR ANGULA
Angular Angula
6 6
CRUD Forms
ADMIN ADMIN
ADMIN
COMMENT TEXT*
Name*
https://investmentnovel.com/angular-6-http-get-example/ 9/10
4/15/2020 Angular 6 Http Get Example Tutorial From Scratch
Email*
Website
SEND
ONE RESPONSE
ZEI
Avatar
An excellent tutorial,
deserves more attention.
https://investmentnovel.com/angular-6-http-get-example/ 10/10