在下面的配置中,要打开给定路径的模态,分配给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'
},
});
}
}());