【问题标题】:$uibModal not loading correct content on first click$uibModal 在第一次点击时没有加载正确的内容
【发布时间】:2019-01-14 18:09:08
【问题描述】:

我在 ServiceNow 中工作并尝试使用 $uibModal 打开一个包含嵌入式小部件的模式窗口。模态在第一次单击时打开良好,但之后的每次单击都需要两次单击才能使模态加载正确的内容。我在一些网站上读到这是因为模板缓存不清除,有些人建议不要使用脚本标签,但我不确定如何在没有 ServiceNow 中的脚本标签的情况下让 uibModal 工作。有没有人遇到过这个?很想得到一些关于如何解决这个问题的建议。

这是我的客户端脚本:

c.onWidget2 = function(template, task) {
    c.taskName = task.short_description;
    c.modalInstance = $uibModal.open({
        templateUrl: template,
        scope: $scope,
        size: 'lg'
    });
    spUtil.get('hrj_task_activity_scoped', {
        sys_id: task.sys_id,
        table: 'sn_hr_core_task',
        recordInfo: task.taskInfo
    }).then(function(response) {
        c.newTask2 = response;
    });
};

//closeModal for the "x" 
c.closeModal = function() {
    c.modalInstance.close();
};

这是我的 HTML:

<div class="card" ng-click="c.onWidget2('newTask2',task);"></div>

<script>
    <div class="panel panel-default">
        <div class="panel-heading clearfix">
            <h4 class="panel-title pull-left">{{c.taskName}}</h4>
      <span ng-click="c.closeModal()"><i class="fa fa-times pull-right"></i></span>
    </div>
        <sp-widget widget="c.newTask2" options="c.newTaskOptions"></sp-widget>
  </div>
</script>

【问题讨论】:

    标签: angularjs modal-dialog servicenow angular-templatecache


    【解决方案1】:

    这里的问题是“模态指令”,就像在这个线程中一样:

    Integrating directive in Angular UI Modal

    解决方案是在模态渲染后加载指令:

    c.onWidget2 = function(template, task) {
        c.taskName = task.short_description;
    
        var initWidget =  spUtil.get('hrj_task_activity_scoped', {
            sys_id: task.sys_id,
            table: 'sn_hr_core_task',
            recordInfo: task.taskInfo
        }).then(function(response) {
            c.newTask2 = response;
        });
    
        c.modalInstance = $uibModal.open({
            templateUrl: template,
            scope: $scope,
            size: 'lg'
        }).rendered.then(initWidget);
    };
    
    //closeModal for the "x" 
    c.closeModal = function() {
        c.modalInstance.close();
    };
    

    【讨论】:

      猜你喜欢
      • 2021-08-12
      • 2013-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-20
      • 1970-01-01
      相关资源
      最近更新 更多