diff --git a/src/elasticsearch.angular.js b/src/elasticsearch.angular.js index 0bfa86952..67b6fa1e8 100644 --- a/src/elasticsearch.angular.js +++ b/src/elasticsearch.angular.js @@ -11,12 +11,12 @@ process.angular_build = true; /* global angular */ angular.module('elasticsearch', []) - .factory('esFactory', ['$http', '$q', function ($http, $q) { + .factory('esFactory', ['$injector', '$q', function ($injector, $q) { var factory = function (config) { config = config || {}; config.connectionClass = AngularConnector; - config.$http = $http; + config.$injector = $injector; config.defer = function () { return $q.defer(); }; diff --git a/src/lib/connectors/angular.js b/src/lib/connectors/angular.js index 543745be1..489f92a76 100644 --- a/src/lib/connectors/angular.js +++ b/src/lib/connectors/angular.js @@ -12,16 +12,24 @@ var ConnectionFault = require('../errors').ConnectionFault; function AngularConnector(host, config) { ConnectionAbstract.call(this, host, config); - this.defer = config.defer; - this.$http = config.$http; - if (this.host.auth) { - this.$http.defaults.headers.common.Authorization = 'Basic ' + (new Buffer(this.host.auth, 'utf8')).toString('base64'); - } + var connector = this; + + config.$injector.invoke(function ($http, $q) { + connector.$q = $q; + connector.$http = $http; + + if (connector.host.auth) { + connector.$http.defaults.headers.common.Authorization = 'Basic ' + (new Buffer(connector.host.auth, 'utf8')).toString('base64'); + } + }); + + } _.inherits(AngularConnector, ConnectionAbstract); AngularConnector.prototype.request = function (params, cb) { - var abort = this.defer(); + var abort = this.$q.defer(); + this.$http({ method: params.method, url: this.host.makeUrl(params),