Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access $templateCache from the console

Tags:

angularjs

I want to check the content of the $templateCache by accessing it from the devtool's console.

I tried the solution given at: https://stackoverflow.com/a/24711132.

This didn't work for me.

How can i do that?

like image 754
Vinay K Avatar asked Mar 12 '15 09:03

Vinay K


2 Answers

I tried this approach just now and get a defined template:

This is my predefined template:

<script type="text/ng-template" id="template.html">
    <div class="modal-content">
        <div class="modal-header">
        </div>
        <div class="modal-body">
        </div>
        <div class="modal-footer">
        </div>
    </div>
</script>

On the Chrome devtools console (supposed name of your application is "ng-app"):

> var ngAppElem = angular.element(document.querySelector('[ng-app]') || document);
> ngAppElem.injector().get('$templateCache').get('template.html')
> "
        <div class="modal-content">
            <div class="modal-header">
            </div>
            <div class="modal-body">
            </div>
            <div class="modal-footer">
            </div>
        </div>
  "
> 

I got help from this snippet: https://gist.github.com/mzgol/7893061

like image 107
okanozeren Avatar answered Oct 14 '22 17:10

okanozeren


One-liner for lazy people:

angular.element(document.body).injector().get('$templateCache').get('<your/file.html or key>')
like image 25
JanisP Avatar answered Oct 14 '22 18:10

JanisP