Skip to main content


Returns an array of all found TemplateRef which belong to the current element and all its children. If the element is not specified, then the current fixture is used.

  • ngMocks.findTemplateRefs( fixture?, directive )
  • ngMocks.findTemplateRefs( debugElement?, id )
  • ngMocks.findTemplateRefs( debugElement?, [attribute, value?] )

or simply with selectors which are supported by ngMocks.find.

  • ngMocks.findTemplateRefs( cssSelector?, [attribute, value?] )

Assume, that a template has the next code.

<ng-template myTpl="header"></ng-template><ng-template myTpl="footer"></ng-template>

Then, we can find ng-template like that:

// returns 2 elementsconst allByDirective = ngMocks.findTemplateRef(MyTplDirective);
// returns 2 elementsconst allByAttribute = ngMocks.findTemplateRef(['myTpl']);
// returns 1 elementconst onlyHeaders = ngMocks.findTemplateRef(['myTpl', 'header']);
// returns 1 elementconst onlyFooters = ngMocks.findTemplateRef(['myTpl', 'footer']);
// returns 0 elementsconst empty = ngMocks.findTemplateRef(['myTpl', 'body']);

More information can be found in ngMocks.findTemplateRef.