我有一些依赖选择,我想重置所有下一个
<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>
但是如何在ng-change方法中重置选择值?
$scope.applyChanges = function (arg) {
if (!_.isUndefined(arg)) {
arg = "?";
}
};
答案 0 :(得分:1)
如果您说arg = '?'
,则只更改本地变量arg
的值,model.v2
引用的值不会更改。
所以将model
和要更改的属性作为参数传递给函数,如
<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>
然后
$scope.applyChanges = function (model, prop) {
if (!_.isUndefined(model[prop])) {
model[prop] = "?";
}
};