2016-04-14 106 views
3

Q)如何在以下服務中使用以下接口模塊?角度2:如何導入/導出c#生成的模型

如果我有從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 { 
     ... 
    } 

的文件都在:

  • 應用程序/接口/模型。 ts
  • app/services/service.ts

回答

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'; 

此外,它似乎模塊名稱不能包含一個點,因爲它打破了導入

+0

謝謝,我結束了剛剛清理生成的文件和導出所有interf因爲這成爲一種痛苦幹杯。 – Dave