2016-07-02 13 views
0

Mein restangular Aufruf hat eine BaseUrl in einer Konfigurationsdatei auf http://localhost:3000/ festgelegt. So ein Anruf wiekann ich eine Basis-URL für expect() setzen

Restangular.all("awards").customPOST(award) 

Anrufe bei baseUrl+"awards"

Nun, wenn ich einen Test für dieses schreibe, muss ich schreiben:

httpBackend.expectPOST("http://localhost:3000/awards") 

Aber später, wenn dieser baseUrl changes, werde ich ändern es in vielen vielen .expect() Methoden.

Gibt es trotzdem eine baseUrl für die expect-Methode, in einer Konfigurationsdatei irgendwo?

Damit das erwarten Methode etwas wie-

httpBackend.expectPOST(baseUrl + "awards"); 

So, dass jede Änderung in der baseUrl keine Änderung Verfahren im expect() erfordert?

Antwort

0

Sie können eine angular.constant erstellen und diese Konstante dann injizieren, wo immer sie benötigt wird.

var app = angular.module('app', []); 
app.constant('Configuration', { 
    BASE_URL: 'http://localhost:3000/' 
}); 

app.factory('RestApiService', function($http, Configuration) { 
    var awardApi = Configuration.BASE_URL + '/awards'; 

    return { 
    getAwards: fucntion() { 
     return $http.get(awardApi); 
    }; 
    }; 
}); 
+0

Vielen Dank !! Es hat perfekt funktioniert !! –

+0

Gern geschehen. Es wäre cool wenn du die Antwort abstimmst;) –