Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Backend
Hey, I have this bandscheme in mongo:
JavaScript
BandSchema = new Schema({
    name: String,
    genre: String,
    cdlist:
    [{
        cd: Cd
    }]
},
{
    timestamps: true
});


this cd scheme:
JavaScript
const CdSchema = new Schema({
    madeinyear: String,
    madeincountry: String,
    name: String,
    image: String,
    songs:
    [{
        // Deze lijst gaat dus song objecten bevatten.
        song: Song
    }]
});

Frontend
And this is what I a trying to do in angular/typescript

JavaScript
import {Band} from '../shared/models/band.model';
import {Cd} from '../shared/models/cd.model';
//import {nummer} from '../shared/models/nummer.model';
import {BandsService} from '../shared/services/band.service';
import {FormControl, FormGroup, Validators} from '@angular/forms';
import {ActivatedRoute} from '@angular/router';
import {Component, Input, OnInit} from '@angular/core';

@Component({
  selector: 'app-addEdit-band',
  templateUrl: './addEdit-band.component.html',
  styleUrls: ['./addEdit-band.component.css']
})
export class addEditBandComponent implements OnInit {
  clickMessage = '';
  cds: Cd[] = new Array<Cd>();
  id: number;
  constructor(private bandsService: BandsService) { }

  ngOnInit() {
  }

  onAddCdClick(cd:string) {
    if (cd) {
      this.cds.push({'name': cd});
    }
  }


  addBand(name, genre) {
      console.log(name,genre);
      //const nummer = new Nummer();
      const band = new Band({ 'name': name,
         'genre': genre , 'cdlist': this.cds
        ]
      console.log('band', band);
      this.bandsService.addBand(band);
  }
}


The problem here is it wont add the cd name to the array, even tho it does add 2 objects to the database(2 empty objects with an _id).

What I have tried:

I have tried it on alot of different ways.
Posted
Updated 7-Apr-18 5:18am
v6

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900