Check if "text / ng-template" exists

I am writing a small tool for which I need to check if a specific ng-pattern is defined. All my templates are defined like this:

<script type="text/ng-template" id="example.html">...</script>


So checking if the file exists via $ http won't work for me. How can I check if a template has been specified? The only option I see so far is DOM validation:

if(angular.element.find('script#example.html').length > 0) { ...


... but I really love the best solution that doesn't need to validate the DOM.


source to share

1 answer

The Script directive puts the content of the template in $ templateCache ( ref. Source ) if it is a template. This means that you have to check if the template exists by checking its presence in the cache:

if ($templateCache.get('example.html')) {
    // template is on the page




All Articles