弹出对话框错误:无法读取未定义的属性“ show”

时间:2019-03-03 22:10:43

标签: asp.net angularjs angular-material

我在使用angularJS显示弹出对话框时遇到问题。我正在尝试与演示站点一起练习。 https://material.angularjs.org/latest/demo/dialog。 以下代码是我的控制器js代码。

(function () {
    'use strict';

    angular
        .module('FramesPopup', ['ngRoute', 'ngMaterial' ])
        .controller('PopupController', PopupController);

    PopupController.$inject = ['$scope'];

    function PopupController($scope, $mdDialog) {
        $scope.title = 'PopupController';
        $scope.status = '  ';
        $scope.customFullscreen = false;

        $scope.showAlert = function (ev) {
            // Appending dialog to document.body to cover sidenav in docs app
            // Modal dialogs should fully cover application
            // to prevent interaction outside of dialog
            $mdDialog.show(
                $mdDialog.alert()
                    .parent(angular.element(document.querySelector('#popupContainer')))
                    .clickOutsideToClose(true)
                    .title('This is an alert title')
                    .textContent('You can specify some description text in here.')
                    .ariaLabel('Alert Dialog Demo')
                    .ok('Got it!')
                    .targetEvent(ev)
            );
        };

        activate();

        function activate() {
            console.log("test");
        }


    }
})();

This is an error message

1 个答案:

答案 0 :(得分:0)

$mdDialog批注列表中缺少$inject服务:

angular
    .module('FramesPopup', ['ngRoute', 'ngMaterial' ])
    .controller('PopupController', PopupController);

̶P̶o̶p̶u̶p̶C̶o̶n̶t̶r̶o̶l̶l̶e̶r̶.̶$̶i̶n̶j̶e̶c̶t̶ ̶=̶ ̶[̶'̶$̶s̶c̶o̶p̶e̶'̶]̶;̶
PopupController.$inject = ['$scope','$mdDialog'];

function PopupController($scope, $mdDialog) {
    $scope.title = 'PopupController';
    $scope.status = '  ';
    $scope.customFullscreen = false;

    $scope.showAlert = function (ev) {
        // Appending dialog to document.body to cover sidenav in docs app
        // Modal dialogs should fully cover application
        // to prevent interaction outside of dialog
        $mdDialog.show(
            $mdDialog.alert()