栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

尝试基于常量在控制器中动态设置templateUrl

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

尝试基于常量在控制器中动态设置templateUrl

我在这里创建了一个插件,
您几乎就在那儿,只是语法是

'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) {        }    });

在这里检查例子



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/436369.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号