File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 11import { Component , OnInit } from '@angular/core' ;
22import { 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}
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments