I have an Angular app with a controller and a service. I call the service from the controller and the service makes a back end call and should call another function in the controller. I was able to call the service from the controller but was not able to call a function in the controller.
Here is the code. The controller:
(function(){
  angular.module("addressModule")
    // The controller for the standardized Address
    .controller('myController', ['$resource','myService', myControllerFunction]);
    myControllerFunction.$inject = ['addressConfig', 'myService', '$resource'];
    function myControllerFunction (addressConfig, myService, $resource, $scope) {
      var vm = this;
      // cannot show what the model is
      vm.model = "some model";
      myService.callGISFromService(vm.model);
      this.callFunctionInController = function(){
        console.log("The controller function is called");
      }
    }
})();
The code for the service is
(function(){
    angular.module('addressModule')
        .service('myService', ['$resource',  myServiceFunction]);
    myServiceFunction.$inject = ['$resource'];
    function myServiceFunction ($resource) {
        this.callGISFromService = function (model) {
            var urlForTheGISCall = "some URL";
            var resource = $resource(urlForTheGISCall);
            console.log("control is in the service");
            resource.get().$promise
            .then(function successCallback(response) {
                this.callFunctionInController();
            }), function errorCallback(response) {
                console.log("the backend call did not work");
            }
        };
    }
})();
I was able to make the back end call and get the data required but not able to call the function in controller.
The error on the console:
TypeError: this.callFunctionInController is not a function
 
     
     
     
    