AngularJS: templateurl function not executing from second time load

218 Views Asked by At

In the below configuration, to open the modal for the given route, the function that is assigned to the templateUrl, executes well for the first time when the modal gets loaded.

But once the value from the routeInfo constant gets returned to the templateUrl on the first time, function does not executes from the second time when the templateUrl is being called, instead takes the values from the cache that was set at the first time.

Please assist? Why?

(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'
             },
         });
}
}());
0

There are 0 best solutions below