我們從.net實體創建一個npm模塊。但是我無法在我的angular2組件上使用它。如何從Typescript上的外部模塊導入類
這就是結構模塊: enter image description here
我想從index.d.ts導入(進入NPM),我們決定,以滿足引用
declare module cio {
export class Address {
addressLine1: string;
addressLine2: string;
city: string;
state: string;
country: string;
postalCode: string;
}
的類型來創建一個模塊。 。 。
declare module cio {
export class Business {
id: string;
typeName: string;
createdDate: Date;
lastModifiedDate: Date;
createdBy: string;
lastModifiedBy: string;
isTest: boolean;
isDeleted: boolean;
taxId: string;
businessType: BusinessType;
businessName: string;
address: Address;
phone: string;
mobile: string;
fax: string;
email: string;
}
enum BusinessType {
Individual = 1,
Company = 2,
}
}
我嘗試使用
import { Address, ... } from 'npm_module_name/index';
導入並創建一個對象像
let testAddress : Address = new Address();
錯誤:(31 16)TS2304:找不到名稱「地址」。
我嘗試使用
import { cio } from 'npm_module_name/index/';
導入並創建一個對象像
let testAddress : cio.Address = new cio.Address();
錯誤:(31,20)TS2694:命名空間 '' * '' 沒有出口構件 '地址' 。
我試圖通過命名空間來替代模塊,但沒有奏效
如何導入我的組件的最佳方式?謝謝
你能更具體地說明你試過的東西和你得到的錯誤嗎?這會幫助我們幫助你。謝謝。 – DeborahK
帶有類的模塊必須對包含要導入它的組件的模塊可見。它是應用程序模塊中的進口數組的一部分嗎? –
@DeborahK我向我的帖子添加更多信息,謝謝。 – nailujpeloz