1

I have an angular service

app.factory('MyService', function($http,$q)){
    return{
        super : function(){
             return "Angular is awesome";
        }
    };
});

and a complex javascript object defined outside Angular's scope (controller or service):

var MyObject = {
    anyFunction : function(){
        alert(MyService.super());
    }
};

Now, doing

MyObject.anyFunction();

of course fails. Any idea how I can get MyService injected into my external javascript object?

0

1 Answer 1

1

This is bad way, byt you may save your angular's var to the localStorage and then acces it from legacy code, and as a second option, you may access global variable from factory, using $window service.

In common js:

var myVar;

In factory:

app.factory('MyService', ['$window', '$http', '$q',function($window, $http, $q)){
    return{
        super : function(){
            $window.myVar = 'that is it';
            //or 
            //localStorage.addItem('myVar', 'varValue');
        }
    };
}]);

after MyService.super is done, you may access var in common js as usualy before

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.