Angular 2:如何导入/导出c#生成的模型

时间:2016-04-14 10:07:36

标签: interface module typescript angular ionic2

问:如何在下面的服务中使用以下接口模块?

如果我从c#生成了以下模型:

declare module App.Core.Model {
    interface Address extends App.Core.Model.BaseEntity {
        addressLine1: string;
        addressLine2: string;
        addressLine3: string;
        area: string;
        countryCode: string;
        name: string;
        postcode: string;
        town: string;
    }
}

服务:

    // these don't work, get "model.ts error is not a module" 
    import {Client} from '../interfaces/model';
    import {AdminUser} from '../interfaces/model';
    import {Building} from '../interfaces/model';


    @Injectable()
    export class AppService {
        ...
    }

文件位于:

  • app / interfaces / model.ts
  • 应用程序/服务/ service.ts

1 个答案:

答案 0 :(得分:0)

您可以执行以下操作(点已被下划线替换):

declare module App_Core_Model {
    export interface Address extends App.Core.Model.BaseEntity {
        addressLine1: string;
        addressLine2: string;
        addressLine3: string;
        area: string;
        countryCode: string;
        name: string;
        postcode: string;
        town: string;
    }
}
 declare module "app_core_model" {
    export = App_Core_Model;
}

然后在导入" app_core_model"时,接口应该可用。模块,例如:

import {Address} from 'app_core_model';

此外,模块名称似乎不能包含点,因为它会破坏导入