Skip to content

Commit

Permalink
Merge 9dda8be into b21ead3
Browse files Browse the repository at this point in the history
  • Loading branch information
calbazasebastian committed Jul 17, 2014
2 parents b21ead3 + 9dda8be commit 8bd6050
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions src/lib/connectors/angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ function AngularConnector(host, config) {
ConnectionAbstract.call(this, host, config);
var connector = this;

config.$injector.invoke(['$http', '$q', function ($http, $q) {
config.$injector.invoke(['$http', '$q','$rootScope', function ($http, $q, $rootScope) {
connector.$q = $q;
connector.$http = $http;
connector.$rootScope = $rootScope;

if (connector.host.auth) {
connector.$http.defaults.headers.common.Authorization = 'Basic ' + (new Buffer(connector.host.auth, 'utf8')).toString('base64');
Expand All @@ -29,24 +30,27 @@ _.inherits(AngularConnector, ConnectionAbstract);

AngularConnector.prototype.request = function (params, cb) {
var abort = this.$q.defer();

this.$http({
method: params.method,
url: this.host.makeUrl(params),
data: params.body,
cache: false,
headers: this.host.getHeaders(params.headers),
transformRequest: [],
transformResponse: []
}).then(function (response) {
cb(null, response.data, response.status, response.headers());
}, function (err) {
if (err.status) {
cb(null, err.data, err.status, err.headers());
} else {
cb(new ConnectionFault(err.message));
}
});
var self=this;
self.$rootScope.$apply(function(){
self.$http({
method: params.method,
url: self.host.makeUrl(params),
data: params.body,
cache: false,
headers: self.host.getHeaders(params.headers),
transformRequest: [],
transformResponse: []

}).then(function (response) {
cb(null, response.data, response.status, response.headers());
}, function (err) {
if (err.status) {
cb(null, err.data, err.status, err.headers());
} else {
cb(new ConnectionFault(err.message));
}
});
});

return function () {
abort.resolve();
Expand Down

0 comments on commit 8bd6050

Please sign in to comment.