One way you can do this is to create a closure variable using IIFE and save the link http serviceoutside the controller and use it in the controller.
(function(){
var _$http;
......
textController.prototype.getData = function(){
var that = this;
_$http({
method: 'GET',
url: 'http://www.filltext.com/?rows=10&fname={firstName}&lname={lastName}' })...
}
angular.module("app").controller("textController",textController);
})();
Plnkr
Or add a property to the constructor instead of its instance.
(function(){
var textController = function($http){
this.greeting="Hello World";
textController._$http = $http;
}
textController.prototype.getData = function(){
var that = this;
textController._$http({
method: 'GET',
url: 'http://www.filltext.com/?rows=10&fname={firstName}&lname={lastName}'})...
}
angular.module("app").controller("textController",textController);
})();
Plnkr
( ng-annotate, )
angular.module("app").controller("textController",['$http', 'blah', textController]);
textController.$inject = ['$http', 'blah'];
ajax- : -
: -
angular.module("app").service('UserService', ['$http', function($http){
this.getUsers = function(searchObj){
return $http({
method: 'GET',
url: 'http://www.filltext.com/?rows=10',
params: searchObj
});
}
}]);
userService .
var textController = function(userSvc){
this.greeting="Hello World";
this.userSvc = userSvc;
}
....
textController.prototype.getData = function(){
var that = this;
this.userSvc.getUsers({firstName:$scope.fn, lastName:$scope.ln}).success(function(data){
that.names=data;
})...;
}
....
angular.module("app").controller("textController",['UserService', textController]);
Plnk3