获取$ mdDialog.alert错误

时间:2016-04-05 08:41:59

标签: javascript angularjs meteor angular-material

我尝试使用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不是函数

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

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

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,以匹配它们注入的顺序......