0

在下面的配置中,为了打开给定路由的模态,分配给 templateUrl 的函数在模态加载时第一次执行良好。

但是一旦 routeInfo 常量的值第一次返回到 templateUrl,函数不会从第二次调用 templateUrl 时开始执行,而是从第一次设置的缓存中获取值。

请协助?为什么?

(function () {
'use strict';

angular
    .module('tzsd.care.cases')
    .config(changeStatusModalConfig)
    .run(['$rootScope', '$templateCache', function ($rootScope, $templateCache) {
        $rootScope.$on('$routeChangeStart', function (event, next, current) {
            if (typeof (current) !== 'undefined') {
                $templateCache.remove(current.templateUrl);
            }
        });
        $rootScope.$on('$viewContentLoading', function (event, viewConfig) {
            var test = 'hi';
            //$templateCache.remove(current.templateUrl);
        });
    }]);

changeStatusModalConfig.$inject = ['$stateProvider', 'modalStateProvider', 'routeInfo'];
function changeStatusModalConfig($stateProvider, modalStateProvider, routeInfo) {
    modalStateProvider
         .state('case.careplan.completeItems', {
             url: '/CompleteItems',
             resolve: {
                 carePlan: ['carePlan', function (carePlan) {
                     return carePlan;
                 }],
                 CarePlanItemClassification: ['CarePlanItemClassification', function (CarePlanItemClassification) {
                     return CarePlanItemClassification;
                 }]
             },
             cache: false,
             replace: true,
             transclude: true,
             modal: {
                 templateUrl: function (carePlan, CarePlanItemClassification) {
                     var modalTypeToOpen = routeInfo.viewControllers.completeMilestonesModal;
                     var selectedProblems = carePlan.getItems(Object.keys(carePlan.selected.items), CarePlanItemClassification.Problem);
                     if (selectedProblems.length > 0) {
                         modalTypeToOpen = routeInfo.viewControllers.completeProblemModal;
                         var incompleteMilestones = selectedProblems.map(
                                             function (problem) {
                                                 return carePlan.items.filter(function (item) {
                                                     return item.parentProblem === problem.id && !item.milestoneOutcome;
                                                 });
                                             }
                                       );
                         if (incompleteMilestones.length)
                             modalTypeToOpen = routeInfo.viewControllers.completeProblemMilestonesModal;
                     }
                     return modalTypeToOpen;
                 },
                 cache: false,
                 replace: true,
                 transclude: true,
                 controller: 'CompleteItemsController',
                 controllerAs: 'popup',
                 size: 'sm',
                 windowClass: 'complete-milestones-modal'
             },
         });
}
}());
4

0 回答 0