如何在angularjs中的模态对话框成功后删除项目

时间:2014-11-06 12:17:26

标签: javascript jquery angularjs modal-dialog

我想在angularjs中按模式对话框上的确定后删除记录。它删除项目但不删除表单$ scope。我在我的html文件中使用$ index。谁能帮我??我很震惊:(

我的html文件:

<script type="text/ng-template" id="admin.html">
<div class="modal-header">
<h3 class="modal-title">Are you Sure?</h3>
</div>
<div class="modal-body">
Are you sure??
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="ok()">OK</button>
<button class="btn btn-warning" ng-click="cancel()">Cancel</button>
</div>
</script>
<button  ng-click="open($index)">Open me!</button>

JS档案:

$scope.open = function (user) {
    var modalInstance = $modal.open({
      templateUrl: 'admin.html',
      controller: 'ModalInstanceCtrl',
      windowClass: 'app-modal-window',
      resolve: {
        userIndex: function () {
            return user
        },
        users: function () {
            return $scope.users
        }
      }
    });

    modalInstance.result.then(function (selectedItem) {
      $scope.selected = selectedItem;
    }, function () {
    });
  };

app.controller('ModalInstanceCtrl', function ($scope, $modalInstance, users, userIndex, services) {

    $scope.users = users;
    $scope.selected = {
        user: $scope.users[userIndex]
    };
  $scope.ok = function () {
    services.deleteCustomer($scope.selected.user.id);
    $scope.users.splice(userIndex, 1);
    $modalInstance.close($scope.selected.user);
  };

  $scope.cancel = function () {
    $modalInstance.dismiss('cancel');
  };
});

0 个答案:

没有答案