2017-04-07 58 views
1

通過Systemjs獲取請求不會將擴展.js添加到url。無法在TypeScript和Systemjs中加載具有擴展js的模塊

這些都是我的打字稿類

customer.ts

import {Address} from "./Address"; 

export class Customer { 
    private _customerName: string = ""; 
    public CustomerAddress: Address = new Address(); 
    public set CustomerName(value: string) { 
     if (value.length == 0) { 
      throw "Customer Name is required"; 
     } 
     this._customerName = value; 
    } 
    public get CustomerName() { 
     return this._customerName; 
    } 
    Validate(): boolean { 
     return this._customerName != ''; 
    } 
} 

address.ts使用

export class Address { 
    public Street1: string = ""; 
} 

以下Systemjs初始化代碼

System.config({ 
     defaultExtension: 'js', 
}); 
System.import("Customer.js").then(function (exports) { 
     var cust = new exports.Customer(); 
}); 

Customer.js是LOA ded成功但Address.js不是。

爲Address.js的GET請求不包含的.js extention 導致以下控制檯請求

GET http://localhost:65401/Address 404 (Not Found). 

我試圖更新customer.ts下面的代碼下面

import {Address} from "./Address.js"; 

但它在語法上是錯誤的,它在VS2013中顯示錯誤。

如何強制Systemjs將擴展「.js」添加到GET請求。

謝謝

回答

1

defaultExtension關鍵字不是頂級配置選項。它需要在packages指令下,請參閱:https://github.com/systemjs/systemjs/blob/master/docs/config-api.md#packages

這就是爲什麼它被忽略並且SystemJS不附加擴展名的原因。您可以定義一個「全局」包,這可能是確保擴展總是附加到每個導入路徑的最簡單方法:

SystemJS.config({ 
    packages: { 
    '.': { 
     defaultExtension: 'js' 
    } 
    } 
}); 
+0

爲我工作。謝謝 !! – Mayank