Backend
Hey, I have this bandscheme in mongo:
BandSchema = new Schema({
name: String,
genre: String,
cdlist:
[{
cd: Cd
}]
},
{
timestamps: true
});
this cd scheme:
const CdSchema = new Schema({
madeinyear: String,
madeincountry: String,
name: String,
image: String,
songs:
[{
song: Song
}]
});
Frontend
And this is what I a trying to do in angular/typescript
import {Band} from '../shared/models/band.model';
import {Cd} from '../shared/models/cd.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 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.