Karl Morrison Karl Morrison - 6 months ago 67
AngularJS Question

$templateCache.get returns undefined

$http.get('template/alert.html', {
cache: $templateCache
});
$scope.clickedButton = function () {
console.log($templateCache.info()); // <-- Object {id: "templates", size: 1}
console.log($templateCache.get('alert.html')); // <-- undefined
console.log($templateCache.get('template/alert.html')); // <-- undefined
};


So I am trying to aquire the html, put it into the cache and then console.log out the contents of the html file.

Answer Source
$http.get('template/alert.html', {
    cache: true
}).then(function(resp){
    $templateCache.put('template/alert.html', resp.data)
});
$scope.clickedButton = function () {
    console.log($templateCache.info()); // <-- Object {id: "templates", size: 1}
    console.log($templateCache.get('template/alert.html')); // <-- response
};

This might work for you