Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

template caching bug #455

Closed
tylercollier opened this Issue · 7 comments

5 participants

@tylercollier

I'm not sure if this is a bug with angular-strap. It might be an angularjs bug.

Here's my original question: http://stackoverflow.com/questions/21655633/angular-strap-tooltip-not-working-in-ng-repeat/21656097?noredirect=1#21656097. It mentions this plunker demo: http://plnkr.co/edit/ZRk2q2Xn6hObUFJ5SIkr?p=preview.

As @calebboyd discovered and answered on stackoverflow, the issue is with template caching.

At https://github.com/mgcrea/angular-strap/blob/v2.0.0-rc.2/src/tooltip/tooltip.js#L80-81, the $templateCache is returning with an array of the previous $http.get() call. That's odd; it should be an object with a .data property. Thus the subsequent code fails without a legit template.

I'm using angular 1.2.2 right now, but the problem also exists with 1.2.12 (as shown by my plunker link). I'm guessing this is an angular bug? Can you confirm?

@calebboyd created a quick solution by replacing those two lines with the following code (or see this plunker: http://plnkr.co/edit/C2L0Pyt1eTW7lM2Tt7Yf?p=info)

return $q.when($templateCache.get(options.contentTemplate) && $templateCache.get(options.contentTemplate)[1] || $http.get(options.contentTemplate, { cache: $templateCache })
              .then(function(response){return response.data}))
              .then(function (contentTemplate) {

I fixed it for myself by not using $templateCache but just using

$http.get(options.contentTemplate, { cache: true })

instead of

$http.get(options.contentTemplate, { cache: $templateCache })
@calebboyd

I see this has already been changed in master. But It doesn't really make sense to keep the template in $http's $cacheFactory. As the user(dev) might want to use it elsewhere. Why not just use a utility method to do something like:

function getTemplate(template){
    return $http.get(template).then(function(response){
        $templateCache.put(template,response.data);
        return response.data;         
    });
}
@tylercollier

It's not fixed in the master dist directory though. See: https://github.com/mgcrea/angular-strap/blob/master/dist/angular-strap.js#L2670.

@mgcrea feel free to close this then but I'm curious as to why you took the caching out altogether with 24545fe. Perhaps you set a default caching option somewhere; I didn't look.

@mgcrea
Owner

@tylercollier I will issue a new release very soon. Dropped the cache support to follow the global $http configuration defined for any app. Indeed having a getTemplate-like function might be interesting to properly leverage $templateCache.

@tylercollier

Awesome. I'll let you close this when you want, or you can leave it open as a reminder. Up to you. Thanks for Angular-Strap and congrats on its success!

@mgcrea mgcrea closed this in aa83097
@morgun

Fix is incorrect both 2.0.5 and 2.1.0 are not working with templates cached by ng-include

Correct fix is to simplify fetchTemplate:
function fetchTemplate(template) {
return $http.get(template, {cache: $templateCache});
}

@mgcrea
Owner

@morgun would be great if you could add an unit test for this.

@Morriz

Can you please fix this asap? It's really creating headaches for me...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.