In my list component, I am getting a model and assigning to array. But getting an error as :
Type '{ setup: string; punchline: string; hide: true; }' is not assignable to type 'Joke'.
Property 'toggle' is missing in type '{ setup: string; punchline: string; hide: true; }'.
here something going wrong. any one help me to fix this issue?
here is my model: (joke.ts)
export class Joke {
public setup:string;
public punchline:string;
public hide:boolean;
constructor(setup:string,punchline:string){
this.setup = setup;
this.punchline = punchline;
this.hide = true;
}
toggle(){
this.hide = !this.hide;
}
}
Here is my component: ( where I am getting error at this.jokes )
import { Component, OnInit } from '@angular/core';
import { Joke } from '../domain-models/joke';
@Component({
selector: 'joke-list',
templateUrl: './joke-list.component.html',
styleUrls: ['./joke-list.component.css']
})
export class JokeListComponent {
jokes:Joke[];
constructor(){
this.jokes = [
{
setup: "What did the cheese say when it looked in the mirror?",
punchline: "Hello-Me (Halloumi)",
hide:true
},
{
setup: "What kind of cheese do you use to disguise a small horse?",
punchline: "Mask-a-pony (Mascarpone)",
hide:false
},
{
setup: "A kid threw a lump of cheddar at me",
punchline: "I thought ‘That’s not very mature’",
hide:true
}
];
}
}
what is wrong here? any one correct me please?