我在这里创建了一个插件,
您几乎就在那儿,只是语法是 'templateProvider'
:
.state('home', { url: '/home', //templateUrl: 'index5templateA.html', (THIS WORKS) // templateUrl: function(CONFIG) { templateProvider: function(CONFIG) { ...doc的片段:
范本
TemplateUrl
…templateUrl也可以是返回url的函数。 它采用一个预设参数stateParams,该参数不会被注入。TemplateProvider
或者您可以使用 模板提供程序 函数,该函数 可以被注入,可以访问locals 并且必须返回模板HTML,如下所示:
因此,在我们的例子中,将是实现:
$stateProvider .state('home', { url: '/home', //templateUrl: 'index5templateA.html', (THIS WORKS) templateProvider: function(CONFIG, $http, $templateCache) { console.log('in templateUrl ' + CONFIG.preCampType); var templateName = 'index5templateB.html'; if (CONFIG.preCampType === "svcc") { templateName = 'index5templateA.html'; } var tpl = $templateCache.get(templateName); if(tpl){ return tpl; } return $http .get(templateName) .then(function(response){ tpl = response.data $templateCache.put(templateName, tpl); return tpl; }); }, controller: function ($state) { } });在这里检查例子



