简体   繁体   中英

How to use the Interface in another component? (getting error)

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM