javascript - ng-model not registering upon form submission -


i playing around ng-if in form. want user able select color (which triggers function ng-change), wants switch colors, selects different color (which triggers different function), , depending on whether switch happens, choose different resulting dropdown menus.

html

<form name = "myform" ng-submit = "submit()">      <label> select color </label>     <select ng-model="mycolor" ng-change = "setcolorselection()" class="form-control"          ng-options = "color color color in colors" required>     </select>     <br>      <label> switch colors? </label> <br>     <label class="radio-inline">         <input type="radio" ng-model="switchcolors" value = "yes" >yes</input>     </label>     <label class="radio-inline">         <input type= "radio" ng-model = "switchcolors" value = "no" >no</input>     </label>     <br>      <div ng-show = "switchcolors == 'yes'">         <label> color switch to? </label>         <select ng-model="mycolorswitched" ng-change = "setcolorselectionswitched()" class="form-control"              ng-options = "color color color in colors">         </select>          <br>     </div>       <label> end result </label>     <div ng-if = "switchcolors == 'no'">         <select ng-model="myendresult" class="form-control"             ng-options = "color color color in colorselection" >         </select>     </div>     <div ng-if = "switchcolors == 'yes'">         <select ng-model="myendresult" class="form-control"             ng-options = "color color color in colorselectionswitched">         </select>     </div>     <br>      <button type = "submit" class = "btn btn-default">submit</button>  </form>  

the form fields populate expected, however, when submit form, req.query.endresult returns undefined server, means ng-model = "myendresult" not submitted. why happening?

as seems, myendresult never get's set value, , therefore null.

assuming initiate "switchcolors" either "no" or "yes" able 1 of ng-if cases set 'myendresult', should check myendresult null , not emptystring. try change following on server:

if (mycolor) req.mycolor = mycolor; if (myendresult) req.myendresult = myendresult; 

if have object in if-clause, check 0, null, undefined of object.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -