1

我正在使用角材料。我正在使用 $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();
            };
        }

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

4

2 回答 2

1

$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();
         };
于 2016-11-16T11:03:22.180 回答
1

你应该使用.hide,

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

编辑:

正如 Ramesh 提到的,你的$ctrl.cancel函数应该放在外面

演示

于 2016-11-16T10:56:08.000 回答