Angular材料$ mdDialog.hide()不起作用

时间:2016-11-16 10:54:15

标签: javascript angularjs angular-material mddialog

我正在使用棱角分明的材料。我正在使用$ mdDialog在我的应用程序上创建弹出窗口。一切正常,但$ mdDialog.hide()不起作用。

       $ctrl.footerModal = function () {
            $mdDialog.show({
                template: '<md-dialog aria-label="Privacy Policy">' +
                '<md-dialog-content>' +
                '<div class="md-dialog-content">' +
                '<h2>Privacy Policy</h2>' +
                '<p> sum has been the industrys standard dummy text ever since the 1500s, when an unknown printer ' +
                'took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, ' +
                'but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s ' +
                ' with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desk</p>' +
                '<p>' +
                '</div>' +
                '</md-dialog-content>' +
                '<md-dialog-actions layout="row">' +
                '<span flex>' + '</span>' +
                '<md-button ng-click="$ctrl.cancel()">' +
                'Ok' +
                '</md-button>' +
                '</md-dialog-actions>' +
                '</md-dialog>',
                parent: angular.element(document.body),
                clickOutsideToClose: true
            });
            $ctrl.cancel = function () {
                $mdDialog.hide();
            };
        }

有谁能告诉我这里我做错了什么

2 个答案:

答案 0 :(得分:2)

您应该使用.hide

$scope.cancel = function() {
   $mdDialog.hide();
};

修改

您的$ctrl.cancel功能应该放在Ramesh提到的外面

<强> DEMO

答案 1 :(得分:0)

请在$ctrl.footerModal函数

之外编写代码

您的代码应为

$ctrl.footerModal = function () {
            $mdDialog.show({
                template: '<md-dialog aria-label="Privacy Policy">' +
                '<md-dialog-content>' +
                '<div class="md-dialog-content">' +
                '<h2>Privacy Policy</h2>' +
                '<p> sum has been the industrys standard dummy text ever since the 1500s, when an unknown printer ' +
                'took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, ' +
                'but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s ' +
                ' with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desk</p>' +
                '<p>' +
                '</div>' +
                '</md-dialog-content>' +
                '<md-dialog-actions layout="row">' +
                '<span flex>' + '</span>' +
                '<md-button ng-click="cancel()">' +
                'Ok' +
                '</md-button>' +
                '</md-dialog-actions>' +
                '</md-dialog>',
                parent: angular.element(document.body),
                clickOutsideToClose: true
            });
         }

 $ctrl.cancel = function () {
             $mdDialog.hide();
         };