1

I am trying to access an Angular function from an existing website with a content script or something similar. I know the function I need to call, but I'm unfamiliar with the scope of Angular functions. So, even though I can see the function, and I know what parameters to pass into it, I can't call it from the console.

Here it the function I need...

angular.module("smartwayTraffic").controller("mapController", ["$scope", "$window", "$q", "$timeout", "$modal", "_", "constant", "geolocation", "dataService", "mapService", function(n, t, i, r, u, f, e, o, s, h) {

...

n.gotoRegion = function(t) {
    e.regionBounds.forEach(function(i) {
        i.region === t && (y(), n.map.control.fitBounds(i.bounds), v())
    })
};

....

What else do I need to trigger this function from the console?

....gotoRegion("Nashville");
6
  • What do you want to do exactly? This sounds like a case of the XY Problem. What is a content script exactly? What is it exactly that limits you to call gotoRegion from "a content script"? Commented Jan 20, 2015 at 14:31
  • You might find this question useful (stackoverflow.com/questions/15527832/…) Commented Jan 20, 2015 at 14:32
  • The problem is that I have to take a screenshot of this website... smartway.tn.gov/traffic for every location in the menu once every 5 minutes. All I have access to is the url and a browser. The previous version of the software I am updating used cookies to zoom into these locations, but as far as I can tell, the new site only wants a geolocation point or it sends you to the wide view. The site menu that will zoom into these areas is calling a function called "gotoRegion()" with the city name as a parameter when you click the link. I am open to other solutions to this problem. Commented Jan 20, 2015 at 14:47
  • As far what I meant by a content script, I am looking to add some kind of code that executes in the browser that manipulates the data that has been loaded. Then, I can add it into the existing script that takes screenshots of this site we already have in place. Commented Jan 20, 2015 at 14:53
  • @tantangula: I'm not sure, but it sounds to me like what you need is a directive for the map. With a directive you are able to manipulate the DOM in whatever way you like, and can avoid writing script methods that should try to force its way into an angular controller scope. Commented Jan 20, 2015 at 16:58

1 Answer 1

1

Yes, you just need to use angular.element to get an element that's within the scope of your controller:

angular.element("yourElement").scope().n.gotoRegion();
Sign up to request clarification or add additional context in comments.

1 Comment

This did work, but I had to traverse the scope hierarchy a little before I got to the function I needed to call. So it ultimately looks like... angular.element(".ng-scope").scope().$$childHead.gotoRegion("Memphis") Thanks!

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.