1

I'm trying to understand how to create a model that includes an array. I am trying to do something like this but I'm getting an error :

ERRROR

Argument of type 'elset' is not assignable to parameter of type 'elset[]'.

MODEL

export class elset{
    constructor(
        public name: string,
        public title: string
    ){}
}
export class pageModel{
    constructor(
        public type: string,
        public set: elset[]
    ){}
}

SERVICE

@Injectable()
export class customService {
    constructor ( ){}

    types = [
        new pageModel('home', 
                     new elset('something','somethingelse')
                     )
    ];
}

1 Answer 1

2

You defined the second parameter as an array of elset instances here:

export class pageModel{
    constructor(
        public type: string,
        public set: elset[]  <--------------------
    ){}
}

So you need to pass an array:

new pageModel('home', [new elset('something','somethingelse')])
Sign up to request clarification or add additional context in comments.

2 Comments

Yep, Thank you. @Maximus, if it is an object then it would be public set: elset{} ? and then I could do new pageModel('home', new elset('something','somethingelse')
simply public set: elset, yes, then you'd be able to do the way you did it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.