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
7ec76fdf
Commit
7ec76fdf
authored
Nov 10, 2017
by
Emile TAVERNE
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ajout pipes orderBy et capitalize
parent
88bfb38a
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
32 additions
and
5 deletions
+32
-5
app.component.html
trombinoscope/src/app/app.component.html
+1
-1
app.component.ts
trombinoscope/src/app/app.component.ts
+0
-2
app.module.ts
trombinoscope/src/app/app.module.ts
+4
-1
card.component.html
trombinoscope/src/app/components/card/card.component.html
+1
-1
capitalize.pipe.ts
trombinoscope/src/app/pipes/capitalize.pipe.ts
+8
-0
index.ts
trombinoscope/src/app/pipes/index.ts
+2
-0
order-by-full-name.pipe.ts
trombinoscope/src/app/pipes/order-by-full-name.pipe.ts
+16
-0
No files found.
trombinoscope/src/app/app.component.html
View file @
7ec76fdf
...
...
@@ -6,6 +6,6 @@
</header>
<div
class=
"w80 center ptm"
>
<div
class=
"grid-4 has-gutter"
>
<app-card
*
ngFor=
"let person of persons"
[
person
]="
person
"
></app-card>
<app-card
*
ngFor=
"let person of persons
| orderByFullName
"
[
person
]="
person
"
></app-card>
</div>
</div>
trombinoscope/src/app/app.component.ts
View file @
7ec76fdf
...
...
@@ -8,8 +8,6 @@ import {DataService} from "./services/data.service";
styleUrls
:
[
'./app.component.css'
]
})
export
class
AppComponent
implements
OnInit
{
private
readonly
nbPerson
:
number
=
10
;
private
persons
:
PersonModel
[]
=
[];
constructor
(
private
dataService
:
DataService
)
{
...
...
trombinoscope/src/app/app.module.ts
View file @
7ec76fdf
...
...
@@ -5,11 +5,14 @@ import {HttpClientModule} from '@angular/common/http';
import
{
AppComponent
}
from
'./app.component'
;
import
*
as
Components
from
'./components'
;
import
*
as
Services
from
'./services'
;
import
*
as
Pipes
from
'./pipes'
;
@
NgModule
({
declarations
:
[
AppComponent
,
Components
.
CardComponent
Components
.
CardComponent
,
Pipes
.
CapitalizePipe
,
Pipes
.
OrderByFullNamePipe
],
imports
:
[
BrowserModule
,
...
...
trombinoscope/src/app/components/card/card.component.html
View file @
7ec76fdf
<div
class=
"card pam mtm tbm"
>
<h2
class=
"txtcenter"
>
{{person.firstname }} {{person.lastname | uppercase}}
</h2>
<h2
class=
"txtcenter"
>
{{person.firstname
| capitalize
}} {{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/pipes/capitalize.pipe.ts
0 → 100644
View file @
7ec76fdf
import
{
Pipe
,
PipeTransform
}
from
'@angular/core'
;
@
Pipe
({
name
:
'capitalize'
})
export
class
CapitalizePipe
implements
PipeTransform
{
transform
(
value
:
string
):
string
{
return
value
.
charAt
(
0
).
toUpperCase
()
+
value
.
slice
(
1
);
}
}
trombinoscope/src/app/pipes/index.ts
0 → 100644
View file @
7ec76fdf
export
*
from
'./capitalize.pipe'
;
export
*
from
'./order-by-full-name.pipe'
;
trombinoscope/src/app/pipes/order-by-full-name.pipe.ts
0 → 100644
View file @
7ec76fdf
import
{
Pipe
,
PipeTransform
}
from
'@angular/core'
;
import
{
PersonModel
}
from
"../../models"
;
@
Pipe
({
name
:
'orderByFullName'
})
export
class
OrderByFullNamePipe
implements
PipeTransform
{
transform
(
value
:
PersonModel
[]):
PersonModel
[]
{
return
value
.
sort
((
a
:
PersonModel
,
b
:
PersonModel
):
number
=>
{
const
fullNameA
=
`
${
a
.
firstname
}
${
a
.
lastname
}
`
;
const
fullNameB
=
`
${
b
.
firstname
}
${
b
.
lastname
}
`
;
if
(
fullNameA
<
fullNameB
)
return
-
1
;
if
(
fullNameA
>
fullNameB
)
return
1
;
return
0
;
});
}
}
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