basickarl
basickarl

Reputation: 40454

$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.

Upvotes: 1

Views: 1391

Answers (2)

lopezvit
lopezvit

Reputation: 384

I have solve it using $templateRequest:

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

Upvotes: 0

santy
santy

Reputation: 310

$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

Upvotes: 1

Related Questions