4

I am trying to edit bus list in browser console for this bus search angualrjs site.

I tried to access the filteredBusData(ng-repeat) list in that page which is used in ng-repeat from console.

Code:

Method 1:

angular.element(document.body).injector().invoke(function ($rootScope)
{
        scope = $rootScope;
        console.log(scope.filteredBusData);
});

Method 2:

angular.element('[ng-controller="busTicketCheckoutCtrl"]').scope;

`busTicketCheckoutCtrl` is the particular controller 

Problem:

Both the methods didn't work :(

Method 1: scope.filteredBusData is undefined

Method 2: Uncaught Error: [jqLite:nosel] Looking up elements via selectors is not supported by jqLite!

Question:

How to access the particular controller scope in the browser console?

Any suggestion/idea will be grateful.

2 Answers 2

4

@jonnyknowsbest Answer is correct but the main thing is site has disabled debug info, you need to first enable it using angular.reloadWithDebugInfo() this command will reload you page. After that you can access to controller object.

And then you could do access angular scope in you console.

angular.element(document.querySelector('[data-ng-controller=busTicketCheckoutCtrl]')).scope()
Sign up to request clarification or add additional context in comments.

4 Comments

@jonnyknowsbest your solution was right just modified it.. Thanks :)
Any idea to use angular.reloadWithDebugInfo() in casperjs.
@karthick.k no bro..I don't have idea about casper.js.but it should be as same as this.just you need to make sure page has loaded .. NOTE please bro don't paste your site URL dirctly here that can harm you in any way..Thanks
@karthick.k Glad to assist you..Thanks you so much :)
2
var scope = angular.element($('[ng-controller=busTicketCheckoutCtrl]')).scope();

If you're not using jQuery, then you want:

var scope = angular.element(document.querySelector('[ng-controller=busTicketCheckoutCtrl]')).scope();

At the moment you are just passing a string into angular.element() and i think it wants an actual element.

2 Comments

change it to angular.element(document.querySelector('[data-ng-controller=busTicketCheckoutCtrl]')) but still not able to access scope using angular.element(document.querySelector('[data-ng-controller=busTicketCheckoutCtrl]')).scope()
Thanks for the info. It is given undefined

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.