0

I am setting data from a angular controller to a service. I need to somehow get this data using jquery or javascript.Is this possible since I am not requesting it from a url?

Angular service

    getSeriesData: function () {
        return this.legendSeries;
    },
    setSeriesData: function (legendSeries) {
        this.legendSeries = legendSeries;
    },

2 Answers 2

1

Not sure why you would want to do that (if you explain the scenario better it might help), but in case you want to share data between an angular application and other JS code (e.g. JSON), one way you could go about is to dispatch a global event from the angular service [for example $(window).trigger('myEvent', myJSON] and then catch this on your separate JS code [window.addEventListener('myEvent'...]

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

2 Comments

that is what I was kind of thinking but was not sure what to search for. thanks! that solves my problem!
cheers. if it works for you feel free to mark the question as answered. :-)
1

Seems like possible using injector

var injector = angular.element('body').injector()

$injector.invoke(function (serviceName) {
    var legendSeries = service.legendSeries;
    service.setSeriesData(legendSeries);
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.