Skip to content

Commit 4a8c00e

Browse files
author
majid noureddine
committed
add appareil compponent
1 parent ef8e16c commit 4a8c00e

File tree

8 files changed

+89
-25
lines changed

8 files changed

+89
-25
lines changed

src/app/app.component.html

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
<div style="text-align:center">
2-
<h1>Welcome to {{ title }}!</h1>
1+
<div class="container">
2+
<div class="row">
3+
<div class="col-xs-12">
4+
<h2>Mes appareils</h2>
5+
<p>Mis à jour le : {{ lastUpdate | async | date: 'd MMMM y' | uppercase }}</p>
6+
<ul class="list-group">
7+
<app-appareil *ngFor="let appareil of appareils"
8+
[appareilName]="appareil.name"
9+
[appareilStatus]="appareil.status"></app-appareil>
10+
</ul>
11+
<button class="btn btn-success"
12+
[disabled]="!isAuth"
13+
(click)="onAllumer()">Tout allumer</button>
14+
</div>
15+
</div>
316
</div>
4-
<app-mon-premier></app-mon-premier>

src/app/app.component.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,40 @@ import { Component } from '@angular/core';
66
styleUrls: ['./app.component.scss']
77
})
88
export class AppComponent {
9-
title = 'my first angular project';
9+
10+
isAuth = false;
11+
lastUpdate = new Promise((resolve, reject) => {
12+
const date = new Date();
13+
setTimeout(
14+
() => {
15+
resolve(date);
16+
}, 2000
17+
);
18+
});
19+
appareils = [
20+
{
21+
name: 'Machine à laver',
22+
status: 'éteint'
23+
},
24+
{
25+
name: 'Frigo',
26+
status: 'allumé'
27+
},
28+
{
29+
name: 'Ordinateur',
30+
status: 'éteint'
31+
}
32+
];
33+
34+
constructor() {
35+
setTimeout(
36+
() => {
37+
this.isAuth = true;
38+
}, 4000
39+
);
40+
}
41+
42+
onAllumer() {
43+
console.log('On allume tout !');
44+
}
1045
}

src/app/app.module.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import { BrowserModule } from '@angular/platform-browser';
22
import { NgModule } from '@angular/core';
3-
4-
import { AppRoutingModule } from './app-routing.module';
53
import { AppComponent } from './app.component';
6-
import { MonPremierComponent } from './mon-premier/mon-premier.component';
4+
import { AppareilComponent } from './appareil/appareil.component';
5+
import { FormsModule } from '@angular/forms';
76

87
@NgModule({
98
declarations: [
109
AppComponent,
11-
MonPremierComponent
10+
AppareilComponent
1211
],
1312
imports: [
1413
BrowserModule,
15-
AppRoutingModule
14+
FormsModule
1615
],
1716
providers: [],
1817
bootstrap: [AppComponent]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<li [ngClass]="{'list-group-item': true,
2+
'list-group-item-success': appareilStatus === 'allumé',
3+
'list-group-item-danger': appareilStatus === 'éteint'}">
4+
<div style="width:20px;height:20px;background-color:red;"
5+
*ngIf="appareilStatus === 'éteint'"></div>
6+
<h4 [ngStyle]="{color: getColor()}">Appareil : {{ appareilName }} -- Statut : {{ appareilStatus }}</h4>
7+
<input type="text" class="form-control" [(ngModel)]="appareilName">
8+
</li>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Component, Input, OnInit } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-appareil',
5+
templateUrl: './appareil.component.html',
6+
styleUrls: ['./appareil.component.scss']
7+
})
8+
9+
export class AppareilComponent implements OnInit {
10+
11+
@Input() appareilName: string;
12+
@Input() appareilStatus: string;
13+
14+
constructor() { }
15+
16+
ngOnInit() {
17+
}
18+
19+
getColor() {
20+
if (this.appareilStatus === 'allumé') {
21+
return 'green';
22+
} else if (this.appareilStatus === 'éteint') {
23+
return 'red';
24+
}
25+
}
26+
}

src/app/mon-premier/mon-premier.component.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/app/mon-premier/mon-premier.component.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)