Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
formation-angular
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Emile TAVERNE
formation-angular
Commits
88bfb38a
Commit
88bfb38a
authored
Nov 10, 2017
by
Emile TAVERNE
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ajout service et récupèration des données
parent
fd88f46a
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
55 additions
and
16 deletions
+55
-16
app.component.ts
trombinoscope/src/app/app.component.ts
+7
-11
app.module.ts
trombinoscope/src/app/app.module.ts
+5
-2
card.component.html
trombinoscope/src/app/components/card/card.component.html
+1
-1
data.service.ts
trombinoscope/src/app/services/data.service.ts
+33
-0
index.ts
trombinoscope/src/app/services/index.ts
+1
-0
environment.prod.ts
trombinoscope/src/environments/environment.prod.ts
+4
-1
environment.ts
trombinoscope/src/environments/environment.ts
+4
-1
No files found.
trombinoscope/src/app/app.component.ts
View file @
88bfb38a
import
{
Component
,
OnInit
}
from
'@angular/core'
;
import
{
GenderEnum
,
PersonModel
}
from
"../models"
;
import
{
PersonModel
}
from
"../models"
;
import
{
DataService
}
from
"./services/data.service"
;
@
Component
({
selector
:
'app-root'
,
...
...
@@ -11,16 +12,11 @@ export class AppComponent implements OnInit {
private
persons
:
PersonModel
[]
=
[];
ngOnInit
():
void
{
for
(
let
i
=
0
;
i
<
this
.
nbPerson
;
i
++
)
{
const
person
=
new
PersonModel
();
person
.
id
=
i
;
person
.
lastname
=
'Tata '
+
person
.
id
;
person
.
firstname
=
'Toto'
;
person
.
email
=
'toto.tata@test.fr'
;
person
.
gender
=
i
%
2
===
0
?
GenderEnum
.
FEMALE
:
GenderEnum
.
MALE
;
constructor
(
private
dataService
:
DataService
)
{
this
.
persons
.
push
(
person
);
}
}
async
ngOnInit
():
Promise
<
any
>
{
this
.
persons
=
await
this
.
dataService
.
getPersons
();
}
}
trombinoscope/src/app/app.module.ts
View file @
88bfb38a
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
:
[
...
...
@@ -10,9 +12,10 @@ import * as Components from './components';
Components
.
CardComponent
],
imports
:
[
BrowserModule
BrowserModule
,
HttpClientModule
],
providers
:
[],
providers
:
[
Services
.
DataService
],
bootstrap
:
[
AppComponent
]
})
export
class
AppModule
{
}
trombinoscope/src/app/components/card/card.component.html
View file @
88bfb38a
<div
class=
"card pam mtm tbm"
>
<h2
class=
"txtcenter"
>
{{person.firstname}} {{person.lastname | uppercase}}
</h2>
<h2
class=
"txtcenter"
>
{{person.firstname
}} {{person.lastname | uppercase}}
</h2>
<img
*
ngIf=
"person.image; else elseBlock"
class=
"center w100"
[
src
]="
person
.
image
"
>
<ng-template
#
elseBlock
>
<img
class=
"center w100"
[
src
]="
defaultImages
.
get
(
person
.
gender
)"
>
...
...
trombinoscope/src/app/services/data.service.ts
0 → 100644
View file @
88bfb38a
import
{
Injectable
}
from
"@angular/core"
;
import
{
HttpClient
}
from
"@angular/common/http"
;
import
{
PersonModel
}
from
"../../models"
;
import
{
environment
}
from
'../../environments/environment'
;
@
Injectable
()
export
class
DataService
{
constructor
(
private
http
:
HttpClient
)
{
}
public
getPersons
():
Promise
<
PersonModel
[]
>
{
return
new
Promise
<
PersonModel
[]
>
((
resolve
,
reject
)
=>
{
this
.
http
.
get
(
environment
.
api
.
persons
).
subscribe
(
data
=>
{
const
results
:
PersonModel
[]
=
[];
data
[
'results'
].
forEach
((
result
)
=>
{
const
person
=
new
PersonModel
();
person
.
id
=
result
[
'id'
][
'value'
];
person
.
firstname
=
result
[
'name'
][
'first'
];
person
.
lastname
=
result
[
'name'
][
'last'
];
person
.
email
=
result
[
'email'
];
person
.
image
=
result
[
'picture'
][
'large'
];
results
.
push
(
person
);
});
resolve
(
results
);
},
err
=>
{
reject
(
err
);
});
});
}
}
trombinoscope/src/app/services/index.ts
0 → 100644
View file @
88bfb38a
export
*
from
'./data.service'
;
trombinoscope/src/environments/environment.prod.ts
View file @
88bfb38a
export
const
environment
=
{
production
:
true
production
:
true
,
api
:
{
persons
:
''
}
};
trombinoscope/src/environments/environment.ts
View file @
88bfb38a
...
...
@@ -4,5 +4,8 @@
// The list of which env maps to which file can be found in `.angular-cli.json`.
export
const
environment
=
{
production
:
false
production
:
false
,
api
:
{
persons
:
'https://randomuser.me/api/?results=20&seed=seed'
}
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment