If I have a method being called within an Angular service how would I be able to call a method within this method? Is it appropriate to create a function inside of a method which resides in a service? Below is an example. The called function modalSuccess
does not fire. Also, trying to use $scope or $rootScope fails along with calling the service name followed by a new method such as last.successModal()
.
angular.module('main').service('last', function($location, $http)
{
this.submit = function(){
function modalSuccess(){
console.log('hello world');
}
modalSuccess() --> does not fire
}
Example with $rootScope does not work either
angular.module('main').service('last', function($location, $http, $rootScope)
{
this.submit = function(){
$rootScope.modalSuccess = function(){
console.log('hello world');
}
$rootScope.modalSuccess() --> does not fire
}
Even adding a new method does not work
angular.module('main').service('last', function($location, $http, $rootScope)
{
this.submit = function(){
this.modalSuccess = function(){
console.log('hello world');
}
last.modalSuccess() --> does not fire, returns an error
}