How to pass $scope of your controller to your $mdDialog?

Rahul Kiwitech
Rahul K...
292 Points
26 Posts

Hi,

I working with angular material. I am opening $mdDialog in my controller js and $mdDialog uses template as:

eventApp.controller('FooterController', ['$scope', 'geoService', '$mdDialog',
function ($scope, geoService, $mdDialog) {
$scope.showLoadingMessage = function (show, message) {
$scope.popLoading = show;
$scope.LoadingMessage = message;
};
$scope.contactEvent = function (event) {
$mdDialog.show({
controller: ['$scope', '$mdDialog', '$mdConstant', 'footerService', DialogeventController],
templateUrl: 'event.tmpl.html',
parent: angular.element(document.body),
targetEvent: event,
clickOutsideToClose: true
});
};
}]);
 
function DialogeventController($scope, $mdDialog, $mdConstant, footerService) {
$scope.currencyVal;
$scope.showHints = true;
$scope.submitted = false;
$scope.sendTo = [];
$scope.sendContactMessageEvent = function (form) {
if ($scope[form].$valid) {
$mdDialog.hide();
var contactMessageViewModel = {
Name: $scope.cntName,
Email: $scope.cntEmail,
PhoneNo: $scope.cntPhone,
Category: $scope.cntCategory,
SubCategory: $scope.cntSubCategory,
Message: $scope.cntMessage
};
$scope.showLoadingMessage(true, "Loading");
var getMessageData = footerService.sendContactMessage(contactMessageViewModel);
getMessageData.then(function (d) {
$scope.showLoadingMessage(false, "");
}, function () {
 
});
} else {
$scope.submitted = true;
}
};

In the above I am try to show loading message on form submit in dialog. But unable to do this. It always show message undefined method '$scope.showLoadingMessage'.

Thanks

 

Views: 11076
Total Answered: 2
Total Marked As Answer: 0
Posted On: 20-Jan-2017 07:01

Share:   fb twitter linkedin
Answers
Smith
Smith
2890 Points
78 Posts
         

You can pass the $scope of your controller to your $mdDialog as an example below

$mdDialog.show({
parent: angular.element(document.body),
template: tmpl,
scope: $scope,
controller: 'myCtrl'
});
Posted On: 20-Jan-2017 07:10
Rahul Maurya
Rahul M...
4918 Points
28 Posts
         

You can pass the $scope of your controller to your $mdDialog as:

eventApp.controller('FooterController', ['$scope', 'geoService', '$mdDialog',
function ($scope, geoService, $mdDialog) {
$scope.showLoadingMessage = function (show, message) {
$scope.popLoading = show;
$scope.LoadingMessage = message;
};
$scope.contactEvent = function (event) {
$mdDialog.show({
controller: ['$scope', '$mdDialog', '$mdConstant', 'footerService', DialogeventController],
templateUrl: 'event.tmpl.html',
parent: angular.element(document.body),
targetEvent: event,
scope: $scope,
preserveScope: true,
clickOutsideToClose: true
});
};
}]);

 

Posted On: 20-Jan-2017 07:14
 Log In to Chat