出现 $mdDialog.alert 错误

Getting $mdDialog.alert error

我正在尝试使用 Angular Material Design 激活警报对话框。

在我的控制器中,我有:

angular.module('KidHubApp')
  .controller('ActivityCtrl', ['$scope','$meteor', '$stateParams', '$mdDialog', '$state', function($scope, $meteor, $stateParams, $state, $mdDialog){

...

$mdDialog.show(
$mdDialog.alert()
.clickOutsideToClose(true)
.title('No timeslot selected.')
.textContent('Please select a date and a timeslot to make a reservation.')
.ok("Got it!")
.targetEvent(ev)
      );
}

但是,我正在进入控制台:

TypeError: $mdDialog.alert is not a function

我该如何解决这个问题?

您的函数参数与注入顺序不匹配...

angular.module('KidHubApp')
  .controller('ActivityCtrl', ['$scope','$meteor', '$stateParams', '$mdDialog', '$state', function($scope, $meteor, $stateParams, $state, $mdDialog){

应该是

angular.module('KidHubApp')
  .controller('ActivityCtrl', ['$scope','$meteor', '$stateParams', '$mdDialog', '$state', function($scope, $meteor, $stateParams, $mdDialog, $state){

交换函数参数中的 $state$mdDialog,以匹配它们注入的顺序...