I tried a lot of methods from some sources but still cannot solve the problem of the close button of the predefined html dialog of material angularjs. When I pressed the outside area of dialog, it can be closed normally.
The error message I get using Batarang Angular is cancel is undefined.
var app = angular.module('MyApp', ['ngMaterial', 'ngMessages', 'material.svgAssetsCache'])
app.controller('AppCtrl', function($scope, $mdDialog) {
$scope.showTermUseDialog = function(ev) {
$mdDialog.show({
controller: DialogController,
contentElement: '#termUseDialog',
parent: angular.element(document.body),
targetEvent: ev,
clickOutsideToClose: true,
scope: $scope,
preserveScope: true
});
};
function DialogController($scope, $mdDialog) {
$scope.hide = function() {
$mdDialog.hide();
};
$scope.cancel = function() {
$mdDialog.cancel();
};
}
});
Full code can view at here:
http://codepen.io/skylee91/pen/xRoLXo
If the angular material version is 1.1.0, the code run as expected. But currently I am using the latest stable build 1.1.1, the close button is not fire the ng-click event.
You have to add scope and preservescope to the showTermUseDialog
$scope.showTermUseDialog = function(ev) {
$mdDialog.show({
controller: DialogController,
contentElement: '#termUseDialog',
parent: angular.element(document.body),
targetEvent: ev,
clickOutsideToClose: true,
scope: $scope,
preserveScope: true
});
};
And also add a call to close in the html; ng-click="close()"
See plnkr here: http://plnkr.co/edit/c1tCfQVMcyj7ZtKRiTOa?p=preview
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