Errormessage
Argument of type '{ 'name': string; }' is not assignable to parameter of type 'Cd'.
Property 'id' is missing in type '{ 'name': string; }'.
My model
import {Nummer} from './nummer.model';
export class Cd {
_id?: number;
name:string;
image?: string;
madeinyear?: number;
madeincountry?: string;
songs?: Nummer[];
get id(): number {
return this._id;
}
set id(value: number) {
this._id = value;
}
get _name(): string {
return this.name;
}
set _name(value: string){
this.name = value;
}
get _image(): string {
return this.image;
}
set _image(value: string){
this.image = value;
}
get year(): number {
return this.madeinyear;
}
set year(value: number) {
this.madeinyear = value;
}
get country(): string {
return this.madeincountry;
}
set country(value: string) {
this.madeincountry = value;
}
get numbers(): Nummer[] {
return this.songs;
}
set numbers(value: Nummer[]) {
this.songs = value;
}
constructor(values: Object = {}) {
Object.assign(this, values);
}
}
My Typescript code
<pre>
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 = '';
cdlist: Cd[] = new Array<Cd>();
id: number;
constructor(private bandsService: BandsService) { }
ngOnInit() {
}
onAddCdClick(cd:string) {
if (cd) {
this.cdlist.push({'name': cd});
}
}
addBand(name, genre) {
console.log(name,genre);
const band = new Band({ 'name': name,
'genre': genre , 'cdlist': this.cdlist});
console.log('band', band);
this.bandsService.addBand(band);
}
}
What I have tried:
I tried making everything optional in my model, this did not result in anything good.