categorie-create.component.ts 1.2 KB

123456789101112131415161718192021222324252627282930
  1. import { Component, OnInit } from '@angular/core';
  2. import { Categorie } from '../categorie';
  3. import { CategorieService } from '../categorie.service';
  4. import { Router } from '@angular/router';
  5. import { FormsModule } from '@angular/forms';
  6. @Component({ selector: 'app-categorie-create', imports: [FormsModule], templateUrl: './categorie-create.component.html', styleUrl: './categorie-create.component.css'})
  7. export class CategorieCreateComponent
  8. {
  9. categorie: Categorie = new Categorie();
  10. constructor(private categorieService: CategorieService, private router: Router) { }
  11. ngOnInit(): void { }
  12. saveCategorie() { this.categorieService.createCategorie(this.categorie).subscribe({
  13. next: (params) => { console.log('params', params); this.goToListCategorie(); },
  14. error: (err: any) => { console.log(err); },
  15. complete: () => { }
  16. }); }
  17. onSubmit(){ console.log(this.categorie); this.saveCategorie(); }
  18. goToListCategorie() {this.router.navigate(['/categorie-list'], { queryParams: { 'refresh': this.getRandomInteger(1, 100000) } }); }
  19. private getRandomInteger(min: number, max: number) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min)) + min; }
  20. }