gpt4 book ai didi

javascript - $mdDialog 和 Controller

转载 作者:搜寻专家 更新时间:2023-11-01 04:56:27 24 4
gpt4 key购买 nike

我有两个 $mdDialog 想在两个不同的 View 中使用,每个 View 的 Controller 完全相同。我想要的是在每个 Controller 中都有 $mdDialog.show() 函数,传递一个对象和一个 Controller 文件来完成工作。

但是当我尝试这样做时,我收到一条错误消息,提示未定义 DialogCtrl。

例如,在 View Controller 中:

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
});

};

然后我的对话 Controller :

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
});
};

}

最佳答案

尝试将 Controller 名称放在引号下:

$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 }
})

这将消除错误。

关于javascript - $mdDialog 和 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37188872/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com