简体   繁体   中英

Template is not taken from $templateCache

I have this code https://gist.github.com/domakas/8b574aa919e64085c569

The problem is, that when I compile the element, it doesn't load template from $templateCache. In fact it doesn't trigger link or controller callbacks. There are no errors in console, it just seems that it stops working when it reaches link callback. If I try to $templateCache.get('../templates/companySelector.html') before compilation, I can see that template is there.

I have istanbul set-uped so I can clearly see, that link is not executed. '../templates/companySelector.html' module is generated by ng-html2js and tests are ran by karma.

In the gist the template url is:

templateUrl: '../templates/companySelector.html'

However you say the template is at src/templates/companySelector.html .

Please check to make sure that the path inside your gist is the actual path to the correct template based on the "index" page you are running from and not the location of the directive codebase.

After lots of investigation, I managed to find out that request for template is not made at all, since requests are async, it needs to be flushed (the same as any $http request is flushed) only after flushing cache is actually looked up and taken to use. So use $httpBackend.flush() after element compile.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM