Just add a controller to your constructor, and you can attach it to the instance as a property, like any other property.
customer.RequestCtrl = function ($http) {
this.person = {};
this.searching = false;
this.selectedInstitute = null;
this.query = null;
this.institutes = null;
this.$http = $http;
};
customer.RequestCtrl.$inject = ['$http'];
customer.RequestCtrl.prototype.search = function() {
...
this.$http({method: 'GET', url: '/api/institutes', params: {q: this.query, max: 250}})
...
};
Another way is to add a variable and start protecting your controller in IIFE.
(function(customer){
var $httpSvc;
customer.RequestCtrl = function ($http) {
this.person = {};
this.searching = false;
this.selectedInstitute = null;
this.query = null;
this.institutes = null;
$httpSvc = $http;
};
customer.RequestCtrl.prototype.search = function() {
...
$httpSvc({method: 'GET', url: '/api/institutes', params: {q: this.query, max: 250}})
...
};
angular.module('app').controller('RequestCtrl', ['$http', customer.RequestCtrl]);
})(customer);
source
share