有Angular JS:
$scope.changeSelect = function (item){
if(item == 0){
// Здесь изменить ng-model элемента
}
}
HTML:
<select ng-model="city" ng-change="changeSelect(city)">
<select ng-model="country" ng-change="changeSelect(country)">
如果条件为真,我需要为每个ng-model
重置ng-change
当我调用函数ng-change="changeSelect()"
时,我需要检查零值,如果为真,则将此ng-model值更改为null。更新了问题
答案 0 :(得分:0)
试试这个
<select ng-model="city" ng-change="changeSelect(this.city)">
<select ng-model="country" ng-change="changeSelect(this.country)">
$scope.changeSelect = function (item){
if (item == 0) {
item=null;
}
}
另一种方法是手动思考方式:p
<select ng-model="city" ng-change="changeSelect(this.city,'city')">
<select ng-model="country" ng-change="changeSelect(this.country,'country')">
.........
$scope.changeSelect = function (item, selectedContex) {
if (item == 0) {
if (selectedContex == "city") {
$scope.city = null;
return false;
}
else if (selectedContex = 'country') {
$scope.country = null;
return false;
}
}
}
答案 1 :(得分:0)
HTML:
<select ng-model="(changeSelect(city) ? null: city)">
脚本:
$scope.changeSelect = function (item){
if(item == 0){
return true;
}
else {
return false;
}
}
答案 2 :(得分:0)
您可以使用我撰写的angular-reset-on指令。使用此指令,您可以指定重置每个字段的条件。
例如:
<select ng-model="city" ng-reset-on="city == 0">
<select ng-model="country" ng-reset-on="country == 0">
就这么简单。 :)