angularjs - Use ng-controller inside angular templates -


i passing ng-controller attribute in ng-template script tag as,

<script type="text/ng-template" id="dirtemplate.html" ng-controller="tmplctrl">.

but variables inside controller scope not available inside template.

jsfiddle above code available at, http://jsfiddle.net/hb7lu/21925/

you can 1 of 2 ways not how you're doing it.

add ng-controller div consuming ng-include

<body ng-app="myapp">   <script type="text/ng-template"  id="dirtemplate.html">      {{tmplvalue}}   </script>    <span ng-include="'dirtemplate.html'" ng-controller="tmplctrl"></span> </body> 

http://jsfiddle.net/hb7lu/21927/

or

add ng-controller in nested div inside template

<body ng-app="myapp">     <script type="text/ng-template"  id="dirtemplate.html">       <div ng-controller="tmplctrl">{{tmplvalue}}</div>     </script>      <span ng-include="'dirtemplate.html'"></span> </body> 

http://jsfiddle.net/pkpbwee9/1/


Comments

Popular posts from this blog

Capture and play voice with Asterisk ARI -

c++ - Can not find the "fiostream.h" file -

visual studio - Installing Packages through Nuget - "Central Directory corrupt" -