Dynamic models using ng-if - AngularJS form -
here code:
as can see, displayed if q.answer == 'fail'
- value of select box further in page.
if "fail" has been selected, user can select defect type saved question.failure.type
.
my question is, if user selects "fail" , selects defect type - , changes "fail" else. question.failure.type
still retained, though ng-if
false now. how can make question.failure.type
no longer in model if ng-if
false?
<div class="panel panel-danger" ng-if="q.answer == 'fail'"> <div class="panel-heading"> <h3 class="panel-title">comments</h3> </div> <div class="panel-body"> <form novalidate name="failureform"> <div class="row"> <div class="col-xs-12"> <select name='defect' class='form-control' ng-model='question.failure.type' ng-options='item item in defecttypes' required> <option value=''>select defect type...</option> </select> ...
edit: added new code requested
<div ng-repeat="q in questions" ng-show="standard.servicetype"> <div class="panel panel-info"> <div class="panel-heading"> <h3 class="panel-title">{{ $index + 1 }}. <span ng-bind="q.questiontext"></span></h3> </div> <div class="panel-body"> <answer-field question="q"></answer-field> </div> </div> ... code in example above appears
assuming value of q.answer
assigned in <input>
element in html, can clear value of question.failure.type
based on conditional expression using ng-change
.
for example:
<input ng-bind='q.answer' ng-change='question.failure.type = (q.answer == 'fail' ? question.failure.type : undefined)' >
this trivial example, setting question.failure.type
either value has or undefined
, depending on if q.answer == 'fail'
or not.
Comments
Post a Comment