2015-01-07 86 views
0

我正在創建一個網站與Angularjs和WebAPI作爲後端支持與Visual Studio。與angularjs環境特定的配置

我已經定義的URL app.config.js到的WebAPI作爲一個應用程序不變:

var serviceBase = 'http://localhost/Webapiservice/'; 
    app.constant('ngAppSettings', { 
     apiServiceBaseUri: serviceBase, 
     clientId: 'ngTestApp' 
    }); 

現在對於QA環境(http://QAServer/Webapiservice/),在的WebAPI駐留在不同的URL,同樣也適用於我們的生產環境(http://ProdServer/Webapiservice/)。

我可以手動將js文件更新到適當的位置。但有沒有辦法使這個過程自動化,以便webAPI指向正確的URL?

是否可以用grunt做到這一點?我再次從未使用過咕嚕聲。

+0

哪個服務器,你正在主持的網站? – V31

回答

0

ngConstant做得很好,連同grunt:https://github.com/werk85/grunt-ng-constant。通過這種方式,您可以將環境指定爲JSON文件並在編譯/運行時,grunt使用模塊(我稱爲我的總是ENV)生成一個enviornment.js文件,該文件可以注入應用程序的每個部分。

0

我會做這樣的事情:

angular 
    .module('app', []) 
    .value('$path', { 
     rest : "http://localhost/Webapiservice" 
    }) 

你要給這樣的事情:

app.constant('ngAppSettings', { 
    apiServiceBaseUri: $path.rest, 
    clientId: 'ngTestApp' 
});