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


我该如何解决?

最佳答案

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

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

关于javascript - 出现$ mdDialog.alert错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36421272/

10-09 14:47