Compléter le code afin de rendre l'application fonctionnelle.
Voici un exem...
✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.
Compléter le code afin de rendre l'application fonctionnelle.
Voici un exemple de fonctionnement de l'application : (2 captures ci-dessous)
Capture 1 :
Capture 2 :
Code ajout.component.ts
import { Component, OnInit } from '@angular/core';import { ActivatedRoute, Router } from '@angular/router';import { BiblioService } from '../biblio.service';import { Livre } from '../livre';@Component({ selector: 'app-ajout', templateUrl: './ajout.component.html', styleUrls: ['./ajout.component.css']})export class AjoutComponent implements OnInit { edit = false; l: Livre; constructor( public biblio: BiblioService, private route: ActivatedRoute, private router: Router ) { this.l = new Livre(); } ngOnInit(): void { this.edit = false; // vérifie si le composant est appelé avec un titre this..subscribe(params => { const id = .get('titre'); if (id !== null) { this.edit = true; this.biblio.getSinglePerson(id).subscribe(response => { this.l = response; }, error => { console.log(error); } ); } }); } onSubmit(): void { // Vérifions qu'il y a au moins un titre. if (this.l.titre === '') { alert('Il faut au moins un titre'); return; } if (this.edit) { this.biblio.updateOnServer(this.l.titre, this.l); } else { this.biblio.addToServer(this.l); } this..navigate(['/list']); }}