首页 > 解决方案 > Angular 接口出现未定义

问题描述

我在我的控件中有一个接口,我用它来实例化:

共享:IShared;

我进口的:

从'./../../interfaces/i-shared'导入{IShared};

这是我的接口代码:

import { IAddress } from './i-address';
import { IEmail } from "./i-email";
import { IPhone } from "./i-phone";
import { IBusiness } from './i-business';

export interface IShared {
        owner_id:string;
        card_color:string;
        card_name:string;
        card_type:string;
        card_subtitle:string;
        company:string;
        title:string;
        linkedin:string;
        linkedin_bus:string;
        facebook:string;
        google:string;
        twitter:string;
        pinterest:string;
        emails: IEmail[];
        phones: IPhone[];
        addresses: IAddress[];
        businesses: IBusiness[];

} 

但是,当我尝试将某些内容推送到“this.shared.phones”时,我得到了错误:

ERROR TypeError: Cannot read property 'phones' of undefined

我在这里做错了什么?

标签: angular

解决方案


推荐阅读