[英]Change the folder location for Angular ui-bootstrap templates
I am trying to use ui-bootstrap.min.js with the external templates. 我正在尝试将ui-bootstrap.min.js与外部模板一起使用。
The error I am getting is: 我得到的错误是:
http://localhost:13132/Place/template/timepicker/timepicker.html 404 (Not Found)
I would like for every page, for every template, it to look for my templates under: 我想为每个页面,每个模板,它在下面寻找我的模板:
http://localhost:13132/js/app/template/...
but I cannot seem to find where I could change the location where this is pointing to. 但我似乎无法找到我可以改变指向的位置。
Anyone know how to make this change? 有谁知道怎么做这个改变?
This can be handled using $provide.decorator
这可以使用$provide.decorator
来处理
Read more about this issue: https://github.com/angular-ui/bootstrap/issues/743 阅读有关此问题的更多信息: https : //github.com/angular-ui/bootstrap/issues/743
myApp.config(function($provide) {
$provide.decorator('datepickerDirective', function($delegate) {
//array of datepicker directives
$delegate[0].templateUrl = "my/datepicker.html";
return $delegate;
});
});
Update: I've tested this solution and it does work for other templates as well, and only requires those small changes to app.js. 更新:我已经测试了这个解决方案,它也适用于其他模板,只需要对app.js进行一些小的更改。 I've tested this now with timepicker.html and day.html, defining a decorator for timepickerDirective and daypickerDirective. 我现在用timepicker.html和day.html测试了这个,定义了timepickerDirective和daypickerDirective的装饰器。 The latter is used to override the calendar table display. 后者用于覆盖日历表显示。 The templateUrl path is relative to your app folder, in my case it was "partials/fragments/day.html" . templateUrl路径相对于您的app文件夹,在我的例子中它是“partials / fragments / day.html” 。
Per this issue on github, the templateUrl is not configurable. 根据github上的这个问题 ,templateUrl是不可配置的。 You could change the templateUrl property in each directive definition 您可以在每个指令定义中更改templateUrl属性
.directive('accordion', function () {
return {
restrict:'EA',
controller:'AccordionController',
transclude: true,
replace: false,
templateUrl: 'template/accordion/accordion.html'
};
but that would be brittle and hard to maintain. 但那将是脆弱的,难以维持。 Unfortunately, it doesn't look like they're going to make this configurable - but the thread is an interesting read. 不幸的是,它看起来不像是可配置的 - 但线程是一个有趣的读物。
Another alternative without changing code is to add some sort of virtual server directory that maps /Place/template
to your actual location of /js/app/template/
另一种不更改代码的替代方法是添加某种虚拟服务器目录,将/Place/template
映射到/js/app/template/
实际位置
The implementation of virtual directories is obviously in your server platform of choice. 虚拟目录的实现显然是您选择的服务器平台。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.