Home > Software design >  How to use the Interface in another component? (getting error)
How to use the Interface in another component? (getting error)

Time:06-11

Why I am getting this error, I am setting my constructor in componentA like this,

constructor(
     private aaaa: AAAA
     .
     .
     .
     private customizePayload: CustomizePayload
 ){}

this CustomizePayload is in the model.ts class

export interface CustomizePayload {
    itemId: string;
    itemVersion: number;
    locale: string;
    originalItemId: string;
    originalItemVersion: number;
    programId: string
    programNames: string[];
    targetMode: string;
    } 

When I run my app locally I am getting this error:

vendor.js:2 Uncaught Error: Can't resolve all parameters for ContentRowComponent: ([object Object], [object Object], [object Object], [object Object], [object Object], ?).

Basically, I want to use the CustomizePayload interface and set its attribute values in componentA.

CodePudding user response:

That's not the correct way to add an interface to a component. You're injecting it as if it were a dependency, which it's not.

Remove what you have from the constructor and import it into your component like this:

import { CustomizePayload } from 'app/_models/customize-payload.model';

Or wherever it is in your app.

  • Related