I have two $mdDialog
that I want to used in two different views, the controller is the exact same for each. What I want is to have the $mdDialog.show()
function in each controller, passing an object and the one controller file to do the work.
But when I try this I get an error saying DialogCtrl is not defined.
For Example, In the 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
});
};
Then my dialog 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
});
};
}
Try putting controller name under quotes:
$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 }
})
This will remove the error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With