gentos gentos - 10 months ago 34
jQuery Question

angularjs expose service property to $scope

I am trying to expose an angular service property to $scope, to use it in the view my code looks like this

/**API Post SERVICE for user login*/
function login(username,password){
return $'/api/login/',{
}).then(loginSuccessFn, loginErrorFn);

function loginSuccessFn(data, status, headers, config){

window.location = '/';
function loginErrorFn(data, status, headers,config){
console.error("Epic Failure");

so when the $http method returns error and the function loginErrorFn() is called, the response data to be passed in the view, so I may raise an bootstrap alert

How can i achieve this ?


@Karim was right, just something missed there:

when you inject $rootScope inside the service:

 $rootScope.$emit('httpCall', 'success');
 $rootScope.$emit('httpCall', 'failure');

and when you catch it the:

$rootScope.$on('httpCall', function(e,p){scope.isSuccess = p;})

The $rootScope.$on('httpCall', function(e,p){} has two parameteres