2016-10-10 1 views
0

Je l'état ui-routeur suivant pour un de mes onglets:angulaire paramètre caché ui-routeur au contrôleur MVC

$stateProvider 
     .state('systems', { 
      url: '/Tabs/System', 
      templateUrl: function ($stateParams) { 
       return ('/Tabs/Systems/IndexNoLayout') + (typeof $stateParams.CustomerName === 'undefined' ? '' : '/' + $stateParams.CustomerName); 
      }, 
      params: { CustomerName: '' }, 
      controller: 'systemCtrl' 
     }); 

Un lien vers cet onglet:

<a ui-sref="systems({CustomerName: 'dummyCustomer'})"> 
    Save state 
</a> 

et un contrôleur MVC avec un paramètre optionnel:

public ActionResult IndexNoLayout(string CustomerName){...} 

Ce paramètre est ensuite utilisé dans mon MVC View en utilisant Razor. Le code ci-dessus fonctionne. Mais je voudrais avoir ma définition de templateURL comme suit:

templateUrl: '/Tabs/Systems/IndexNoLayout' 

De cette façon, je pourrais facilement supprimer le templateCache $ sur $ stateChangeStart pour ce point de vue angulaire:

$templateCache.remove(fromState.templateUrl); 

Est-il possible de faire?

Répondre

0

This SO post helped me solve my problem.

Ainsi ma solution:

$stateProvider 
     .state('systems', { 
      url: '/Tabs/System',    
      templateUrl:'/Tabs/Systems/IndexNoLayout', 
      params: { CustomerName: '' }, 
      controller: 'systemCtrl'    
     }); 

Dans mon stateChangeStart de $:

$rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {    

     if (toState.name == "systems") { 
      toState.templateUrl = ('/Tabs/Systems/IndexNoLayout' + (typeof toParams.CustomerName === 'undefined' ? '' : '/' + toParams.CustomerName)); 
     } 

     $templateCache.remove(toState.templateUrl); ...});