kris14an kris14an - 4 years ago 159
AngularJS Question

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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download