我试图在点击Angular按钮时打开一个模态。在btn上调用的函数中,单击我将获得下面提到的代码:
function openAddVideoModal() {
var modalInstance = $mdDialog.show({
templateUrl: 'createDesign.html',
controller: 'createDesignCtrl',
resolve: {
currentUser: function () {
return _this.currentUser;
},
postOptions: function() {
return {"receiverId":0};
}
},
parent: angular.element(document.body),
clickOutsideToClose:true,
fullscreen: false
});
}
但是,当我点击按钮时,我收到此错误消息:
TypeError:$ mdDialog.show不是函数
有人可以帮忙吗?提前谢谢。
答案 0 :(得分:4)
您在控制器工厂函数中以错误的顺序注入依赖
更改强>
.controller('Ctrl', [
'$rootScope', '$scope', '$state', '$mdDialog', '$window', 'CONFIG_CONSTANTS', 'LanguageService',
function($rootScope, $scope, $window, $state, $mdDialog, CONFIG_CONSTANTS, LanguageService) {
To(将$window
从第3位移到第5位)
.controller('Ctrl', [
'$rootScope', '$scope', '$state', '$mdDialog', '$window', 'CONFIG_CONSTANTS', 'LanguageService',
function($rootScope, $scope, $state, $mdDialog, $window, CONFIG_CONSTANTS, LanguageService) {
始终确保必须以类似的顺序使用依赖项,就像在inline array
依赖项中注入它们一样。
答案 1 :(得分:1)
您的注射注释未正确排序:
.controller('Ctrl', ['$rootScope', '$scope', '$state', '$mdDialog',
'$window', 'CONFIG_CONSTANTS', 'LanguageService', function($rootScope,
$scope, $state, $mdDialog, $window, CONFIG_CONSTANTS, LanguageService);