Commit 4e946eef by Emile TAVERNE

Ajout récupèration des données par API

parent ceb4bd18
import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {HttpClientModule} from '@angular/common/http';
import {AppComponent} from './app.component';
import * as Components from './components';
import * as Services from './services';
@NgModule({
declarations: [
AppComponent,
Components.HeaderComponent,
Components.LoaderComponent,
Components.PageTrombinoscopeComponent,
Components.TrombinoscopeCardComponent,
],
imports: [
BrowserModule
BrowserModule,
HttpClientModule
],
providers: [
Services.PersonService
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
export * from './header/header.component';
export * from './loader/loader.component';
export * from './page-trombinoscope/page-trombinoscope.component';
export * from './trombinoscope-card/trombinoscope-card.component';
<div class="spinner">
<div class="double-bounce1"></div>
<div class="double-bounce2"></div>
</div>
.spinner {
width: 40px;
height: 40px;
position: relative;
margin: 100px auto;
}
.double-bounce1, .double-bounce2 {
width: 100%;
height: 100%;
border-radius: 50%;
background-color: #1976D2;
opacity: 0.6;
position: absolute;
top: 0;
left: 0;
-webkit-animation: sk-bounce 2.0s infinite ease-in-out;
animation: sk-bounce 2.0s infinite ease-in-out;
}
.double-bounce2 {
-webkit-animation-delay: -1.0s;
animation-delay: -1.0s;
}
@-webkit-keyframes sk-bounce {
0%, 100% {
-webkit-transform: scale(0.0)
}
50% {
-webkit-transform: scale(1.0)
}
}
@keyframes sk-bounce {
0%, 100% {
transform: scale(0.0);
-webkit-transform: scale(0.0);
}
50% {
transform: scale(1.0);
-webkit-transform: scale(1.0);
}
}
import {Component} from '@angular/core';
@Component({
selector: 'app-loader',
templateUrl: './loader.component.html',
styleUrls: ['./loader.component.scss']
})
export class LoaderComponent {
}
<main bp="grid 3">
<app-trombinoscope-card
*ngFor="let person of persons"
[person]="person">
</app-trombinoscope-card>
<ng-container *ngIf="persons; else loading">
<app-trombinoscope-card
*ngFor="let person of persons"
[person]="person">
</app-trombinoscope-card>
</ng-container>
<ng-template #loading>
<div bp="12">
<app-loader></app-loader>
</div>
</ng-template>
</main>
main {
width: 80%;
margin: 0 auto;
margin: 0 auto 30px;
padding-top: 30px;
grid-gap: 30px;
}
......@@ -10,5 +10,6 @@
img {
width: 100%;
border: 3px solid #a8a8a8;
}
}
export * from './person.service';
import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {environment} from '../../environments/environment';
import {PersonModel} from '../models';
@Injectable()
export class PersonService {
constructor(private httpClient: HttpClient) {
}
private static responseToPerson(data: any): PersonModel {
const person = new PersonModel();
person.id = data.id.value;
person.firstname = data.name.first;
person.lastname = data.name.last;
person.email = data.email;
person.image = data.picture.large;
return person;
}
public async getPersons(length: number = 20, seed: string = 'seed'): Promise<PersonModel[]> {
const options = {
params: {
results: length.toString(),
seed: seed
}
};
const result = await this.httpClient.get<{ results: [] }>(environment.api.persons, options).toPromise();
return result.results.map(element => PersonService.responseToPerson(element));
}
}
export const environment = {
production: true
production: true,
api: {
persons: 'https://randomuser.me/api'
}
};
// This file can be replaced during build by using the `fileReplacements` array.
// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
// The list of file replacements can be found in `angular.json`.
export const environment = {
production: false
production: false,
api: {
persons: 'https://randomuser.me/api'
}
};
/*
* For easier debugging in development mode, you can import the following file
* to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
*
* This import should be commented out in production mode because it will have a negative impact
* on performance if an error is thrown.
*/
// import 'zone.js/dist/zone-error'; // Included with Angular CLI.
......@@ -67,6 +67,7 @@
"as-needed"
],
"object-literal-sort-keys": false,
"object-literal-shorthand": false,
"ordered-imports": false,
"quotemark": [
true,
......@@ -89,4 +90,4 @@
"rulesDirectory": [
"codelyzer"
]
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment