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

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

ubuntu - Bash Script to Check That Files Are Being Created -