单击复选框按钮,将显示文本字段和提交按钮,单击提交按钮应禁用复选框按钮

时间:2016-11-16 00:41:52

标签: javascript java html angularjs

<td>
  <input type="checkbox" ng-model="alert.acknowledged" ng-disabled="alert.acknowledged" ng-click="onacknowledgedClick(alert)"></td>
<td>
<span ng-if="!alert.acknowledgeInProgress">{{alert.acknowledgedComments}}</span>
<div ng-if="alert.acknowledgeInProgress">
    <input type="text" style="height:30px; width:150px" ng-model="alert.acknowledgedComments"/>
    <button type="button" class="btn btn-primary"  ng-click="saveAlert(alert)"> Submit </button>
    <button type="button" class="btn btn-primary"  ng-click="cancelAlert(alert)" data-dismiss="modal"> Cancel </button>
</div>

当我点击复选框按钮时,会弹出带有提交按钮的文本文本字段。在文本字段中输入注释后,当用户单击“提交”按钮时,该复选框将被禁用。任何人都可以给我一些意见吗?当我点击“提交”按钮时,如何禁用复选框按钮?

$scope.saveAlert = function(alert) {
    $scope.alert.acknowledged = true;
    /*alert.acknowledgeInProgress = true;*/
    var alertUrl = $incidentsUrl+ "/" +alert.alertForIncident.incidentID+"/alerts/"+alert.alertID;
    $http.put(alertUrl, alert).then(function(result) {
        alert.acknowledgeInProgress = false;
    });     
}

1 个答案:

答案 0 :(得分:0)

你不需要在复选框上点击ng-只需将ng-model设置为ng-model =&#34; alert.acknowledgeInProgress&#34;复选框将该值设置为true,并将触发输入和按钮的显示。

<td>
      <input type="checkbox" ng-model="alert.acknowledgeInProgress" ng-disabled="alert.acknowledged" ng-click="onacknowledgedClick(alert)"></td>
    <td>
    <span ng-if="!alert.acknowledgeInProgress">{{alert.acknowledgedComments}}</span>
    <div ng-if="alert.acknowledgeInProgress">
        <input type="text" style="height:30px; width:150px" ng-model="alert.acknowledgedComments"/>
        <button type="button" class="btn btn-primary"  ng-click="saveAlert(alert)"> Submit </button>
        <button type="button" class="btn btn-primary"  ng-click="cancelAlert(alert)" data-dismiss="modal"> Cancel </button>
    </div>