2015-04-24 57 views
0
$stateProvider 
     .state('login', { 
      url: '/login', 
      controller: 'LoginController', 
      templateUrl: 'login/login.html', 
      access: 0 
     }) 

狀態提供商在這裏,我想寫如何conditinaly適用於角

$stateProvider 
     .state('login', { 
      url: '/login', 
      controller: 'LoginController', 
      if(isAvailable){ 
       templateUrl: 'login/login.html', 
      } 
     else{ 
      //other url    
      } 

     }) 

有條件我必須表現出兩種觀點的。就是這樣實現的在配置文件本身。請建議

回答

3

是的,使用templateProvider配置與$templateFactory。例如

url: '/login', 
controller: 'LoginController', 
templateProvider: function($templateFactory, availabilityService) { 
    var url = availabilityService.isAvailable() ? 
     'login/login.html' : 'other/url.html'; 
    return $templateFactory.fromUrl(url); 
} 
+0

謝謝。函數($ stateProvider,$ urlRouterProvider,$ sceProvider,$ httpProvider,$ templateFactory) {//}我是否需要注入任何depondancies – Prashobh

+0

@prash'templateProvider'函數是可注入的,所以只需注入你需要的東西(因爲我'已經用'$ templateFactory'和'availabilityService'組成了') – Phil