0

I have some dependent selects and I want to reset all next

<select ng-change="applyChanges(model.v2)"
            ng-model="model.v1" name="v1"
            ng-options="v as v.Name for v in vs" class="form-control" required></select>

<select ng-change="applyChanges(model.v3)" ng-model="model.v2"
            name="v2"
            ng-options="vv as vv.Name for vv in model.v1.v2" class="form-control"
            required ng-disabled="!model.v1"></select>

But how to reset select values on ng-change method ?

$scope.applyChanges = function (arg) {
        if (!_.isUndefined(arg)) {
            arg = "?";
        }

    };
kxyz
  • 802
  • 1
  • 9
  • 32

1 Answers1

1

In your case when you say arg = '?', you are only changing the value of the local variable arg the value referred by model.v2 is not changed.

So pass the model and the property to be changed as arguments to the function like

<select ng-change="applyChanges(model, 'v2')"
            ng-model="model.v1" name="v1"
            ng-options="v as v.Name for v in vs" class="form-control" required></select>

then

$scope.applyChanges = function (model, prop) {
        if (!_.isUndefined(model[prop])) {
            model[prop] = "?";
        }
};
Community
  • 1
  • 1
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531