ng-change后,从控制器重置ng-model值

时间:2016-04-05 20:57:48

标签: javascript angularjs angularjs-ng-repeat angularjs-ng-model

如何在不使用指令的情况下在ngChange之后重置控制器中ng模型的值

<div ng-repeat="i in items">
    <!-- Some DOM comes here -->

    <select ng-model="i.avail" ng-change="changeAvail(i.id, i.avail)">
        <option value="true">Available</option>
        <option value="false">Unavailable</option>
    </select>

    <!-- More DOM follows -->
</div>

控制器中的Javascript如下

$scope.changeAvail = function(itemId, value){
    if(confirm("You cannot undo this action")){
        //Send an ajax request to backend for an irreversible action
    }
    else{
        //Restore input to initial value;
    }
}

我不想仅针对此单一事件实施指令

0 个答案:

没有答案