How to look inside $templateCache and get the existing id's? -- debugging $templateCache

757 views
Skip to first unread message

Derek Lin

unread,
May 29, 2015, 12:33:42 PM5/29/15
to ang...@googlegroups.com
I am using karma to run a directive test.  I am using $templateCache in my project.  More specifically, I am using gulp-angular.

When I do console.log($templateCache.info());
I see LOG: Object{id: 'templates', size: 68}

That means there are 68 templates there, right?

But when I try go access a template by an ID that I think exists, it says undefined.

Is there a way for me to get the list of ID's?

BTW, this is related to this issue.  I can't figure this out yet:

Sander Elias

unread,
May 29, 2015, 1:25:23 PM5/29/15
to ang...@googlegroups.com
Hi Derek,

$templateCahe is based on $chacheFactory. $cacheFactory does not export its cache, so what you want is not possible. At least not without modifying angular itself.
If you really need to debug somethig nasty, you can use the new module.$decorator in 1.4, and decorate the $templateCache. In your decorator you can keep an list with everything that's inserted.

Regards
Sander

Derek Lin

unread,
May 29, 2015, 7:05:12 PM5/29/15
to ang...@googlegroups.com
Hi Sander,

I fixed the real issue.  But I am interested in learning about the module.$decorator.  I couldn't find anything.  It's not mentioned in the official doc: https://docs.angularjs.org/api/ng/function/angular.module

Do I need to dig into the source for details?

Sander Elias

unread,
May 30, 2015, 12:10:33 AM5/30/15
to ang...@googlegroups.com
Hi Derek,


It is mentioned in the change-log, but not very prominently ;)

Regards
Sander

Derek Lin

unread,
May 30, 2015, 1:25:52 AM5/30/15
to ang...@googlegroups.com
Thanks Sander.  I have used the $provide#decorator to decorate services before.  So angular.Module#decorator is similar?  Or if you know how they are different?  But anyways, I'll give it a try when I have time.

Sander Elias

unread,
May 30, 2015, 5:00:51 AM5/30/15
to ang...@googlegroups.com
Hi Derek,

They are the same, with the difference that you can use the module#decorator outside of the config function. So you can decorate service(providers) that you use inside your config function.

Regards
Sander
Reply all
Reply to author
Forward
0 new messages