IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Angular Discussion :

Insérer un objet avec une clé étrangère


Sujet :

Angular

Mode arborescent

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2018
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Juin 2018
    Messages : 13
    Par défaut Insérer un objet avec une clé étrangère
    bonsoir la communauté.
    cmnt vous vous portez ? bien j’espère.
    j'ai encore un soucis avec Angular.
    en faite je n'arrive pas inserer un objet avec clé etrangère pourtant mon web service fonctionne bien lorsque je le teste avec postman(je redige avec spring boot)

    en image: Nom : Capture d’écran du 2021-01-30 17-51-07.png
Affichages : 1790
Taille : 179,8 Ko
    mon objet s'ajoute bien en Bd avec sa catégorie et sa nature

    mais lorque je fais le post depuis Angular ça me retourne une erreur

    en image :Nom : Capture d’écran du 2021-01-30 18-11-03.png
Affichages : 1734
Taille : 189,3 Ko

    et au niveau de la trace backend voila ce que ça m'affiche:
    en image :Nom : Capture d’écran du 2021-01-30 17-57-47.png
Affichages : 1765
Taille : 335,2 Ko

    voila mon code Angular:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    export class AddProduitComponent implements OnInit {
      listNature :Nature[];
      listCategorie:Categorie[];
     
      constructor(public serviceProduit:ProduitService,@Inject(MAT_DIALOG_DATA) public data: any, public toastr:ToastrService,
      public route:Router,public matDialogRef:MatDialogRef<AddProduitComponent>, public form:FormBuilder,public serviceNature:NatureService,
      public serviceCat:CategorieService,private spinner: NgxSpinnerService) { }
     
      ngOnInit(): void {
        if(this.serviceProduit.choixOperation =="A")
        {this.inifForm()};
        this.serviceNature.getAllNature().subscribe(
          reponse=>{
            this.listNature=reponse;
          }
        );
        this.serviceCat.getAllCategorie().subscribe(
          reponse=>{
            this.listCategorie=reponse;
          }
        );
      }
      onSubmit(){
        if(this.serviceProduit.choixOperation =="A"){
          this.addProduit();
        }else{
          this.updateProduit();
        }
      }
      //nature:this.form.group({
        idNature:['']
     // });
      //categorie:this.form.group({});
      inifForm(){
        this.serviceProduit.dataForm=this.form.group({
        idPro:null,
    	  nature:['',[Validators.required]],
    	  categorie: ['',[Validators.required]],
    	  numeroProd:['',[Validators.required,Validators.minLength(4)]],
    	  designaton:['',[Validators.required,Validators.minLength(4)]],
    	  prixAchat:['0',[Validators.required]],
        });
      }
      addProduit(){
        this.serviceProduit.createProduit(this.serviceProduit.dataForm.value).subscribe(
          data=>{
            console.log(data);
            this.toastr.success("le Produit a été Créee avec Succès");
            this.matDialogRef.close();
     
            this.serviceProduit.getAllProduit().subscribe(
              reponse=>{
                this.serviceProduit.listData=reponse;
                console.log(reponse);
              }
            );
            this.route.navigate['/produits'];
          }
        )
      }
      updateProduit(){
        this.serviceProduit.updateProduit(this.serviceProduit.dataForm.value.idPro,this.serviceProduit.dataForm.value).subscribe(
          data=>{
            this.toastr.show("le Produit a été Modifié avec Succès");
            this.matDialogRef.close();
     
            this.serviceProduit.getAllProduit().subscribe(
              reponse=>{
                this.serviceProduit.listData=reponse;
                console.log(reponse);
              }
            );
            this.route.navigate['/produits'];
          }
        )
      }
    }
    ma vue
    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    <div class="row">
        <div class="col-md-12 col-md-offset-2">
            <h1>Produit</h1>
            <form [formGroup]="this.serviceProduit.dataForm" (ngSubmit)="onSubmit()">
                <div class="form-group">
                    <label>Nature</label>
                    <select class="form-control" formControlName="nature" id="nature">
                        <option value="0">-Select-</option>
                        <option *ngFor="let item of listNature" value="{{item.idNature}}">{{item.libNature}}</option>
                    </select>
                </div>
                <div class="form-group">
                    <label>Categorie</label>
                    <select class="form-control" formControlName="categorie" id="categorie">
                        <option value="0">-Select-</option>
                        <option *ngFor="let item of listCategorie" value="{{item.idCat}}">{{item.libCat}}</option>
                    </select>
                </div>
                <div class="form-group">
                    <label>code</label>
                    <input type="text" class="form-control" formControlName="numeroProd" id="numeroProd">
                </div>
                <div class="form-group">
                    <label>Désignation</label>
                    <input type="text" class="form-control" formControlName="designaton" id="designaton">
                </div>
                <div class="form-group">
                    <label>Prix Achat</label>
                    <input type="text" class="form-control" formControlName="prixAchat" id="prixAchat">
                </div>
                <div>
                    <button type="submit" class="btn btn-dark"><i class="fa fa-database"></i>Enregistrer</button>
                    <button type="button" class="btn btn-outline ml-1"[mat-dialog-close]><i class="fa fa-close"></i>Fermer</button>
                </div>
     
            </form>
        </div>
    </div>

    comme le savez déjà, je suis encore nouveau sur Angular.
    please I need your help
    Images attachées Images attachées  

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Erreur avec une clé étrangère
    Par Neuromancien2 dans le forum Requêtes
    Réponses: 7
    Dernier message: 06/06/2008, 09h08
  2. Detection d'objets avec une ombre sur une image
    Par djsid dans le forum Traitement d'images
    Réponses: 19
    Dernier message: 18/06/2007, 16h26
  3. Une appli C++ Builder avec une DLL étrangère
    Par devroot dans le forum C++Builder
    Réponses: 4
    Dernier message: 24/04/2007, 15h17
  4. Problème pour charger un set avec une clé étrangère
    Par sylvainv18 dans le forum Hibernate
    Réponses: 2
    Dernier message: 06/11/2006, 18h08
  5. nommer un objet avec une variable
    Par fatcat dans le forum C++
    Réponses: 4
    Dernier message: 11/12/2005, 16h16

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo