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:
Errormessage
Argument of type '{ 'name': string; }' is not assignable to parameter of type 'Cd'.
Property 'id' is missing in type '{ 'name': string; }'.

My model

JavaScript
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
JavaScript
<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.
Posted
Updated 2-Jul-18 4:01am

1 solution

export class addEditBandComponent implements OnInit {
  ...

  onAddCdClick(cd:string) {
    if (cd) {
      this.cdlist.push(new Cd({ name: cd }));
    }
  }
 
Share this answer
 

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