angular ui.bootstrap - 我正在尝试使用确认对话框(此时真的是任何对话框)

时间:2013-12-02 18:22:06

标签: angularjs angularjs-bootstrap

我在$ modal服务上看here。我正在尝试在用户单击删除按钮时实现确认对话框...

现在我有:

'use strict';

angular.module('dashboard.build').controller('BuildCtrl', ['$scope', '$modal', 'BuildSrvc', function($scope, $modal, BuildSrvc) {
  BuildSrvc.refreshBuilds(function(builds) {
    $scope.builds = builds;
  });

  $scope.deployBuild = function(build) {
  }

  $scope.deleteBuild = function(build) {
    var modalInstance = $modal.open({
      templateUrl: 'html/buildDelete.html',
      controller: 'buildDeleteCtrl',
      resolve: {
        items: ['Delete', 'Cancel']
      }
    });

    modalInstance.result.then(function (selectedItem) {
      $scope.selected = selectedItem;
    }, function () {
      $log.info('Modal dismissed at: ' + new Date());
    });
  }
}]);


angular.module('dashboard.build').controller('buildDeleteCtrl', ['$scope', '$modalInstance', 'data', function($scope, $modalInstance, items) {
  $scope.items = items;
  $scope.selected = {
    item: $scope.items[0]
  };

  $scope.ok = function () {
    $modalInstance.close($scope.selected.item);
  };

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

当我尝试点击删除按钮时,会调用$scope.deleteBuild但我收到错误:Argument 'fn' is not a function, got string。因为我还在学习,所以不确定会发生什么。关于如何纠正这个问题的任何指示?

1 个答案:

答案 0 :(得分:1)

在你的模态决心中,你有:

  resolve: {
    items: ['Delete', 'Cancel']
  }

'items'期望函数成功返回。这与承诺(可能)有关,我现在无法解释,但要修复你的错误试试这个:

resolve: {
    items: function () {
        return ['Delete','Cancel'];
    }
}