HoffZ HoffZ - 2 years ago 243
Javascript Question

How to use AngularJS $templateCache.get()?

I need to cache some HTML files when my Angular controller initializes.

According to Angular $templateCache documentation I can add HTML templates to Angular with:


But I can't get this to work. I've tried to get the template file within the controller and within the module run() function (Plunker). But I can see in the network console that the template is not fetched.

app.run(function($templateCache) {

What am I doing wrong?

Answer Source

You have to fetch html using http request then you can store it in template cache. For example:

$http.get('templ.html', {
    cache: $templateCache
}).then(function(result) {

Updated plunker code here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download