Set A Variable To Be Used Inside An Ng-include Directive

Posted By Weston Ganger

Some angular directives create a new scope such as ng-if or ng-include

If you want to set a variable inside that scope add the ng-init attribute to the element

<pre>
<code class="language-markup">
<div ng-include="path/to/your_template.html" ng-init="my_var = 'hello world';"></div>



Related External Links:

- [](http://stackoverflow.com/questions/17090078/how-to-define-the-variable-used-in-ng-include-directive)

Article Topic:Software Development - Javascript

Date:January 11, 2016