首页 > 解决方案 > mdDialog 不会显示 templateUrl

问题描述

我们的团队正在使用 mdDialog 来调出一个允许用户编辑问卷答案的模式。

    $scope.editQuestionFnct = function(val){
        $scope.editWidget = {};
        //alert(val);
        spUtil.get("gateway_questionnaire_widget", {//call new instance of this widget
            //sys_id: $scope.params.refID,
            task_id: $scope.data.task_id,
            quest_id: val,
            request: 'edit',
            taskTable: $scope.data.task_table,
            questionnaire_table: $scope.params.questionnaireTable,
            serviceID: $scope.params.serviceID,
            refID: $scope.params.refID,
            taskCompleted: false,
            editRequest: true
        }).then(function(response) {
            $scope.editWidget = response;//var to hold widget response to display in modal
            $scope.showPrerenderedDialog('#editQuestion');
        });
    }

    $scope.showPrerenderedDialog = function(name) {
        $mdDialog.show({
            templateUrl: name,
            parent: angular.element(document.body),
            clickOutsideToClose:true
        });
    };

    $scope.closeDialog = function($scope){  //closes angular dialog window
        $mdDialog.hide($scope);
    }

    $scope.closeSummDialog = function($scope){  //closes angular dialog window
        $mdDialog.hide($scope);
    }

<script type="text/ng-template" id="editQuestion">
      <div class="md-dialog-container" >
        <md-dialog style="background-color: #ffffff;" aria-label="edit dialog">
          <md-toolbar style="background-color: #022C68; width: 100%;">
            <h1 class="md-toolbar-tools" style="color: #ffffff;">Edit Response</h1>
          </md-toolbar> 
          <md-dialog-content style="background-color: #ffffff;">
            <div id="editQuestDiv" style="min-width: 700px;">
              <sp-widget widget="editWidget"></sp-widget>
            </div>
          </md-dialog-content>
          <md-dialog-actions layout="row">
            <span flex></span>
            <md-button ng-click="closeDialog()" style="background-color: #022C68; color: #ffffff;">
              Close
            </md-button>
          </md-dialog-actions>
        </md-dialog>
      </div>
    </script>

上面的代码我们遇到了两个问题:

首先,我们没有使用 templateUrl,而是使用了 contentElement,这很有效。使用 contentElement 拉出一个带有需要编辑的问题的模式。但是,当用户从第一次点击中退出,然后点击另一个问题时,会出现第一次点击中出现的相同问题。之后的每次点击只会从第一次点击中提取问题。

在做了一些阅读之后,我们决定尝试使用 templateUrl 来代替,但是使用上面的那个会打开一个没有任何内容的模式:

在此处输入图像描述

有人可以解释我们做错了什么吗?我们是否对 contentElement 做错了,只有第一次点击的问题仍然存在?如果我们要使用 templateUrl,为什么我们的 modal 没有出现?

谢谢!

标签: angularjsservicenowangularjs-materialmddialogng-template

解决方案


推荐阅读