gh9 gh9 - 1 year ago 99
Javascript Question

returning angular promise from function

app.factory('myService', ["$http",function($http){
this.test = function(){
return $'');

app.controller('myController' ['myService',function(mySerivce){
myService.test().then(function(){ console.log("success");});

My issue is, when I call
. Success is never being outputted to the console. What am I doing wrong and why?

Answer Source

The following block of code contains an error

myService.test().then(function() console.log("success"););

This is the correction. You were missing the {} to wrap the contents of your function inside then()

myService.test().then(function() { console.log("success"); } );