Skip to content

Commit 853db7e

Browse files
author
majid noureddine
committed
perform data provided by form
1 parent 3b903bc commit 853db7e

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/app/edit-appareil/edit-appareil.component.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Component, OnInit } from '@angular/core';
22
import { NgForm } from '@angular/forms';
3+
import { AppareilService } from '../services/appareil.service';
4+
import { Router } from '@angular/router';
35

46
@Component({
57
selector: 'app-edit-appareil',
@@ -10,12 +12,16 @@ export class EditAppareilComponent implements OnInit {
1012

1113
defaultOnOff = 'éteint';
1214

13-
constructor() { }
15+
constructor(private appareilService: AppareilService,
16+
private router: Router) { }
1417

1518
ngOnInit(): void {
1619
}
1720

1821
onSubmit(form: NgForm) {
19-
console.log(form.value);
22+
const name = form.value['name'];
23+
const status = form.value['status'];
24+
this.appareilService.addAppareil(name, status);
25+
this.router.navigate(['/appareils']);
2026
}
2127
}

src/app/services/appareil.service.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,17 @@ export class AppareilService {
5353
}
5454
);
5555
}
56+
57+
addAppareil(name: string, status: string) {
58+
const appareilObject = {
59+
id: 0,
60+
name: '',
61+
status: ''
62+
};
63+
appareilObject.name = name;
64+
appareilObject.status = status;
65+
appareilObject.id = this.appareils[(this.appareils.length - 1)].id + 1;
66+
this.appareils.push(appareilObject);
67+
this.emitAppareilSubject();
68+
}
5669
}

0 commit comments

Comments
 (0)