首页 > 解决方案 > 弹出对话框错误:无法读取未定义的属性“显示”

问题描述

我在使用 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");
        }


    }
})();

这是一条错误消息

标签: asp.netangularjsangular-material

解决方案


注释列表$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()

推荐阅读