I have a template which I want to use in many parts of my application. The template contains select box with a model assigned.
I include the template by the means of ng-include
.
<span ng-include="'templateWorking'" ng-init="selectModel=data.field"></span>
and then in template:
<script type="text/ng-template" id="templateWorking">
<select ng-model="selectModel">
<option value="Test1">Test1</option>
<option value="Test2">Test2</option>
</select>
Of course, it does not work since ng-include
creates a new child scope.
It is possible to get it work when I use one model (using dot .
in a model like data.model
).
But how it is possible in this particular case so I can use this template with different models in different controllers?
Besides, I need to dynamically attach a handler to the select
(e.g. ng-change="doSmth()").
Thanks in advance.
For the reference: http://plnkr.co/edit/NiLQyVQGb6X1mA0sVvA1?p=preview