DinisCruz / Book_Practical_AngularJS

Content for 'Practical AngularJS' book published at LeanPub
Apache License 2.0
18 stars 6 forks source link

Add tip on how to run angular code snippets from the chrome inspector #22

Open DinisCruz opened 8 years ago

DinisCruz commented 8 years ago

for example:

get module

angular.module('MM_Graph')

image

run code

angular.element(document).scope().$evalAsync(function() {

alert(42);

})
DinisCruz commented 8 years ago

here is the problem I was having (how to get the list of templates in $templateCache) http://stackoverflow.com/questions/31326614/how-do-i-list-everything-in-the-template-cache

DinisCruz commented 8 years ago

accessing route params values (via angular DI)

el = document.querySelector('.ng-scope');
$app = angular.element(el);
$injector = $app.injector();
$get = $injector.get;
$rootScope = $app.scope();
$get('$routeParams')
DinisCruz commented 8 years ago

getting $templateCache directly

$templateCache =  angular.element(document.querySelector('.ng-scope'))
                         .injector().get('$templateCache')

image

DinisCruz commented 8 years ago

here is one way to access the templateCache value data

Using Heap Snapshot

1) add a variable with it to the Window object

_template_Cache =  angular.element(document.querySelector('.ng-scope'))
                          .injector().get('$templateCache')

2) take a heap Snapshot:

image

3) find the Window object

image

4) inside it find the _templateCache field

image

5) inside it find the get function , open the context and look in the data field

image

Using breakpoint

is to set a break point of the getter and trigger a call to it

_template_Cache.get('abc')

image