import { Component, Input, OnInit } from '@angular/core'; import { ChildActivationEnd,…
- User
import { Component, Input, OnInit } from '@angular/core'; import { ChildActivationEnd, Router } from '@angular/router'; import { DemandeService } from 'src/app/services/demande/demande-service.service'; import { DemandesStageDTO } from 'src/gs-api/src';
@Component({ selector: 'app-details-mvt', templateUrl: './details-mvt.component.html', styleUrls: ['./details-mvt.component.scss'] }) export class DetailsMvtComponent implements OnInit { selectedIdToDelete ? = -1; demande!:DemandesStageDTO constructor(private router:Router, private demandeService: DemandeService) { }
ngOnInit(): void { this.demande = this.demandeService.getDemande()!;
}import { Injectable } from '@angular/core'; import { DemandesStageDTO } from 'src/gs-api/src';
@Injectable({ providedIn: 'root' }) export class DemandeService { demande: DemandesStageDTO | null = null; constructor() { } saveDemande(demande: DemandesStageDTO) { this.demande = demande; }
getDemande(): DemandesStageDTO | null { return this.demande; } }import { Component, EventEmitter, OnInit, Output } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { DemandeService } from 'src/app/services/demande/demande-service.service'; import { LinkedinAuthService } from 'src/app/services/linkeidn-auth/linkedin-auth.service'; import { DemandeAPIService, DemandesStageDTO, ProjetDeStageDTO, StagiaireDTO, UtilisateurDTO } from 'src/gs-api/src';
@Component({ selector: 'app-form-application', templateUrl: './form-application.component.html', styleUrls: ['./form-application.component.scss'] }) export class FormApplicationComponent implements OnInit { demande!:DemandesStageDTO; linkedInUser = { id: '', firstName: '', lastName: '',
}
stagiaire:StagiaireDTO={ id:10 } constructor( private demandeService: DemandeService,private linkedAuthService:LinkedinAuthService ,private router:Router,private route:ActivatedRoute, private demande_service: DemandeAPIService) { } projets!: ProjetDeStageDTO; selectedProjet: ProjetDeStageDTO | null = null;
setSelectedProjet(projet: ProjetDeStageDTO): void { this.selectedProjet = projet; } ngOnInit(): void { this.route.queryParams.subscribe((params) => { console.log('StagiairesComponent ngOnInit', params); if (params['code']) { this.linkedAuthService.exchangeCodeForToken(params['code']); } }); this.linkedInUser.id = localStorage.getItem('linkedInId')!; this.linkedInUser.firstName = localStorage.getItem('linkedInFirstName')!; this.linkedInUser.lastName = localStorage.getItem('linkedInLastName')!; // this.linkedInUser.email = localStorage.getItem('linkedInEmail')!; console.log(this.linkedInUser.id) this.route.queryParamMap.subscribe((params) => { const projetNom = params.get('projetNom'); const projetDescription = params.get('projetDescription'); const projetId = params.get('projetId');
console.log(projetId) this.selectedProjet = { id: parseInt(projetId!, 10), titre: projetNom!, description: projetDescription! }; console.log(this.selectedProjet) this.stagiaire = {id:this.stagiaire.id}; console.log(this.stagiaire) // Initialize the stagiaire object this.demande = { stagiaire: this.stagiaire, projet_stage: this.selectedProjet }; }); - Assistant
It is likely that the
save10method inDemandeAPIServiceis not returning the expected values for theDemandesStageDTO, which is causing the attributes to be null or undefined when accessing them in thengOnInitmethod ofDetailsMvtComponent.You may need to debug the
save10method and check if it is properly creating and returning theDemandesStageDTOobject with the correct values. Additionally, make sure that theDemandesStageDTOattributes are properly initialized before calling theenregistrerDemandemethod. - User
no its fine but in mvtdetails component when i call the service in console its undefined this.demande
- Assistant
If
this.demandeis undefined in theDetailsMvtComponent, it could be because theDemandeServicedid not properly save theDemandesStageDTOobject or it was not retrieved correctly.You may want to check if the
saveDemandemethod inDemandeServiceis properly saving theDemandesStageDTOobject. Additionally, you can add console logs to check if thegetDemandemethod inDemandeServiceis properly returning the saved object.Another possibility is that the
ngOnInitmethod inDetailsMvtComponentis being called before thesaveDemandemethod inDemandeServiceis called, which is whythis.demandewould be undefined. In this case, you may want to make sure that thesaveDemandemethod is called before navigating to theDetailsMvtComponent.