|
1 |
| -# Angular API Project |
| 1 | +# :zap: Angular API Project |
2 | 2 |
|
3 |
| -* App using a DataService with httpClient to get json data from an external API. |
| 3 | +* App using a DataService with httpClient to get a JSON Observable data stream from an API and display it using the Angular async pipe. |
4 | 4 | * App also submits a simple Contact form.
|
5 | 5 | * **Note:** to open web links in a new window use: _ctrl+click on link_
|
6 | 6 |
|
|
9 | 9 | 
|
10 | 10 | 
|
11 | 11 |
|
12 |
| -## Table of contents |
| 12 | +## :page_facing_up: Table of contents |
13 | 13 |
|
14 |
| -* [Angular API Project](#angular-api-project) |
15 |
| - * [Table of contents](#table-of-contents) |
16 |
| - * [General info](#general-info) |
17 |
| - * [Screenshots](#screenshots) |
18 |
| - * [Technologies](#technologies) |
19 |
| - * [Setup](#setup) |
20 |
| - * [Code Examples](#code-examples) |
21 |
| - * [Features](#features) |
22 |
| - * [Status & To-Do List](#status--to-do-list) |
23 |
| - * [Inspiration](#inspiration) |
24 |
| - * [Contact](#contact) |
| 14 | +* [:zap: Angular API Project](#:zap-angular-api-project) |
| 15 | + * [:page_facing_up: Table of contents](#page_facing_up-table-of-contents) |
| 16 | + * [:books: General info](#books-general-info) |
| 17 | + * [:camera: Screenshots](#camera-screenshots) |
| 18 | + * [:signal_strength: Technologies](#signal_strength-technologies) |
| 19 | + * [:floppy_disk: Setup](#floppy_disk-setup) |
| 20 | + * [:computer: Code Examples](#code-examples) |
| 21 | + * [:cool: Features](#features) |
| 22 | + * [:clipboard: Status & To-Do List](#status--to-do-list) |
| 23 | + * [:clap: Inspiration](#inspiration) |
| 24 | + * [:file_folder: License](#file_folder-license) |
| 25 | + * [:envelope: Contact](#contact) |
25 | 26 |
|
26 |
| -## General info |
| 27 | +## :books: General info |
27 | 28 |
|
28 | 29 | * Routing module allows user to navigate between Home, About and Contact pages.
|
29 |
| -* API json/image data displayed: firstname, lastname and avatar. |
| 30 | +* API json/image data displayed: firstname, lastname, email and avatar. |
30 | 31 | * Angular FormBuilder used to allow user to submit a form with name and message. Form uses validation.
|
31 |
| -* Simple app. |
| 32 | +* Styling is pure SCSS |
32 | 33 |
|
33 |
| -## Screenshots |
| 34 | +## :camera: Screenshots |
34 | 35 |
|
35 |
| -. |
36 |
| -. |
| 36 | +. |
| 37 | +. |
37 | 38 |
|
38 |
| -## Technologies |
| 39 | +## :signal_strength: Technologies |
39 | 40 |
|
40 |
| -* [Angular v12](https://angular.io/) |
41 |
| -* [RxJS Library v6](https://angular.io/guide/rx-library) used to [subscribe](http://reactivex.io/documentation/operators/subscribe.html) to the API data [observable](http://reactivex.io/documentation/observable.html). |
| 41 | +* [Angular v13](https://angular.io/) |
| 42 | +* [RxJS Library v7](https://angular.io/guide/rx-library) used to [subscribe](http://reactivex.io/documentation/operators/subscribe.html) to the API data [observable](http://reactivex.io/documentation/observable.html). |
42 | 43 | * [The HttpClient in @angular/common/http](https://angular.io/guide/http) offers a simplified client HTTP API for Angular applications that rests on the XMLHttpRequest interface exposed by browsers.
|
43 | 44 |
|
44 |
| -## Setup |
| 45 | +## :floppy_disk: Setup |
45 | 46 |
|
46 | 47 | * Run `npm i` to install dependencies
|
47 | 48 | * Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
|
48 | 49 |
|
49 |
| -## Code Examples |
| 50 | +## :computer: Code Examples |
50 | 51 |
|
51 |
| -* `home.component.ts` |
| 52 | +* `data.service.ts` ES6 arrow function to return observable from API using `apiResponse` interface |
52 | 53 |
|
53 | 54 | ```typescript
|
54 |
| -import { Component, OnInit } from "@angular/core"; |
55 |
| -import { DataService } from "../data.service"; |
56 |
| - |
57 |
| -@Component({ |
58 |
| - selector: "app-home", |
59 |
| - templateUrl: "./home.component.html", |
60 |
| - styleUrls: ["./home.component.scss"] |
61 |
| -}) |
62 |
| -export class HomeComponent implements OnInit { |
63 |
| - users: Object; |
64 |
| - |
65 |
| - constructor(private data: DataService) {} |
66 |
| - |
67 |
| - // on init the Dataservice getUsers() function supplies a user array object. |
68 |
| - ngOnInit() { |
69 |
| - this.data.getUsers().subscribe(data => { |
70 |
| - this.users = data; |
71 |
| - console.log(this.users); |
72 |
| - }); |
73 |
| - } |
| 55 | +getUsers = (): Observable<apiResponse> => { |
| 56 | + return this.http.get<apiResponse>("https://reqres.in/api/users"); |
74 | 57 | }
|
75 | 58 | ```
|
76 | 59 |
|
77 |
| -* `data.service.ts` |
| 60 | +* `home.component.ts` ng init. function to get observable data for the template async pipe - note: using an ES6 arrow function here would result in nothing being displayed, due the use of 'this' |
78 | 61 |
|
79 | 62 | ```typescript
|
80 |
| -import { Injectable } from "@angular/core"; |
81 |
| -import { HttpClient } from "@angular/common/http"; |
82 |
| - |
83 |
| -@Injectable({ |
84 |
| - providedIn: "root" |
85 |
| -}) |
86 |
| -export class DataService { |
87 |
| - constructor(private http: HttpClient) {} |
88 |
| - |
89 |
| - getUsers() { |
90 |
| - return this.http.get("https://reqres.in/api/users"); |
91 |
| - } |
92 |
| -} |
| 63 | +ngOnInit () { |
| 64 | + this.users$ = this.data.getUsers(); |
| 65 | +}; |
93 | 66 | ```
|
94 | 67 |
|
95 |
| -## Features |
| 68 | +## :cool: Features |
96 | 69 |
|
97 | 70 | * API web link could be changed to get different and more complex data.
|
98 | 71 |
|
99 |
| -## Status & To-Do List |
| 72 | +## :clipboard: Status & To-Do List |
100 | 73 |
|
101 |
| -* Status: Working. Updated may 2021. |
| 74 | +* Status: Working. |
102 | 75 | * To-Do: Nothing.
|
103 | 76 |
|
104 |
| -## Inspiration |
| 77 | +## :clap: Inspiration |
105 | 78 |
|
106 | 79 | * [Gary Simon of Coursetro Tutorial: Angular 7 Tutorial - Learn Angular 7 by Example](https://coursetro.com/posts/code/171/Angular-7-Tutorial---Learn-Angular-7-by-Example)
|
107 | 80 |
|
|
0 commit comments