我想在两个不同的视图中使用两个$mdDialog
,控制器对于每个视图完全相同。我想要的是在每个控制器中都有$mdDialog.show()
函数,传递一个对象和一个控制器文件来完成工作。
但是当我尝试这个时,我得到一个错误,说没有定义DialogCtrl。
例如, 在视图控制器中:
angular.module('myApp')
.controller('myViewController', [
'$scope',
'$mdDialog',
myViewController
]);
function myViewController($scope, $mdDialog, myObj) {
var obj = myObj;
vm.showDialog = function(event) {
$mdDialog.show({
controller: DialogCtrl,
templateUrl: 'partials/dialog.html',
clickOutsideToClose: false,
parent: angular.element(document.body),
targetEvent: event,
openFrom: {left: 1500},
closeTo: {left: 1500},
locals: { object: obj }
})
.then(function(response) {
//do stuff
});
};
然后我的对话控制器:
angular.module('myApp')
.controller('DialogCtrl', [
'$scope',
'$mdDialog',
'object',
DialogCtrl
]);
function DialogCtrl( $scope, $mdDialog, object ) {
$scope.obj = object;
$scope.answer = function(answer) {
$mdDialog.hide({
answer: answer,
dataToPass: $scope.obj.name
});
};
}
答案 0 :(得分:11)
尝试将控制器名称置于引号下:
$mdDialog.show({
controller: 'DialogCtrl',
templateUrl: 'partials/dialog.html',
clickOutsideToClose: false,
parent: angular.element(document.body),
targetEvent: event,
openFrom: {left: 1500},
closeTo: {left: 1500},
locals: { object: obj }
})
这将删除错误。