javascript - ng-if wrapping a select ng-options breaks ngModel? -



javascript - ng-if wrapping a select ng-options breaks ngModel? -

this question has reply here:

angularjs ng-model doesn't work within ng-if 5 answers

this plunker angular ngoptions sample:

ngoption/select angular sample

however, added ngif first select resulting in:

<div ng-if="1<2"> color (null not allowed): <select ng-model="mycolor" ng-options="color.name color in colors"></select><br> </div>

something interesting may notice ngif breaks ngmodel binding , nil happens when alter selection.

because same code without ngif produces expected results.

can please confirm if bug in angular, code and/or if there work around it?

using ng-if directive creates new scope dom within it. reference mycolor variable on parent scope, write ng-model="$parent.mycolor"

<div ng-if="1<2"> color (null not allowed): <select ng-model="$parent.mycolor" ng-options="color.name color in colors"></select><br> </div>

javascript angularjs

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -