categorie-update.component.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132
  1. import { Component, OnInit, ViewChild } from '@angular/core';
  2. import { ActivatedRoute, Router } from '@angular/router';
  3. import { MenuComponent } from '../menu/menu.component';
  4. import { Categorie } from '../../interfaces/categorie';
  5. import { CategorieService } from '../../services/categorie.service';
  6. import { FormsModule, NgForm } from '@angular/forms';
  7. @Component({ selector: 'app-categorie-update', imports: [FormsModule, MenuComponent], templateUrl: './categorie-update.component.html', styleUrl: './categorie-update.component.css' })
  8. export class CategorieUpdateComponent implements OnInit
  9. {
  10. @ViewChild('formRef') categorieForm!: NgForm;
  11. numeroCategorie: number = 0;
  12. categorie: Categorie = new Categorie();
  13. constructor(private categorieService: CategorieService, private route: ActivatedRoute, private router: Router, private menu: MenuComponent) { }
  14. ngOnInit()
  15. {
  16. this.numeroCategorie = this.route.snapshot.params['numeroCategorie'];
  17. this.categorieService.getByIdCategorie(this.numeroCategorie).subscribe(data => { this.categorie = data; });
  18. }
  19. updateConfirmed() { if (this.categorieForm.valid) { this.categorieService.updateCategorie(this.numeroCategorie, this.categorie).subscribe(() => { this.goToListCategorie(); }); } }
  20. deleteConfirmed() { this.categorieService.deleteCategorie(this.numeroCategorie).subscribe(() => { this.goToListCategorie(); }); }
  21. goToListCategorie() { this.router.navigate(['/categorie-list', this.menu.getRandomInteger(1, 100000)]); }
  22. }