kris14an
kris14an

Reputation: 751

Angular template directive binding

I wrote single file with directive templates. This file is appended to document using ng-include directive. Sometimes browser load templates before directive template binding, but not always.

https://plnkr.co/edit/SNhVU6BoM0nbOelJpepE?p=preview

Is there some solution to wait after ng-include directive apply html content to document and after that bind directive templates? Maybe should i use different solution to load these templates to html document.

Upvotes: 0

Views: 85

Answers (1)

Petr Averyanov
Petr Averyanov

Reputation: 9476

Angular has 2 builtin possibilities:

  1. Yout template should be in file directly included in your 'index.html'. (Sync templates)
<script src="templates.js"></script>
in which:
app.run(function($templateCache) {
  $templateCache.put('templateId', '<div></div>')
})
  1. Each template should be in separate file template1.html, templat2.html... (Async templates)

P.S. During development templates are always in separate html files, for production usage templates are gathered to js files using build tools.

Upvotes: 1

Related Questions