Monday, 15 March 2010

javascript - Ng-include: access child models -



javascript - Ng-include: access child models -

i have template want utilize in many parts of application. template contains select box model assigned.

i include template means of ng-include.

<span ng-include="'templateworking'" ng-init="selectmodel=data.field"></span>

and 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, not work since ng-include creates new kid scope. possible work when utilize 1 model (using dot . in model data.model).

but how possible in particular case can utilize template different models in different controllers? besides, need dynamically attach handler select (e.g. ng-change="dosmth()").

thanks in advance.

for reference: http://plnkr.co/edit/nilqyvqgb6x1ma0svva1?p=preview

in case best utilize directive instead. can command on ng-include using onload if that's not enough, using directive best bet.

reference: difference between onload , ng-init in angular

javascript angularjs angularjs-scope angularjs-ng-include angularjs-ng-init

No comments:

Post a Comment