gpt4 book ai didi

javascript - Gulp Angular 构建模板缓存问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:45:50 27 4
gpt4 key购买 nike

我的 build.js 使用 ngHtml2js 将指令中的部分转换为 js 文件。

gulp.task('partials', function () {
return gulp.src('src/{components,app}/**/*.html')
.pipe($.ngHtml2js({
moduleName: 'testApp'
}))
.pipe(gulp.dest('.tmp'))
.pipe($.size());
});

我的指令位于 components->directives 的 components 文件夹中。

问题是,当我尝试部署 dist 文件夹时,来自路由 JS 文件的静态部分调用被触发,我收到 404。

angular.module(ModuleName)
.directive('collapseWindow', ['$parse', function (parse) {

return {
templateUrl:'/components/directives/collapse.html',
transclude:true,
restrict: 'A'

在我的理解中,ngHtml2js 将部分转换为 module.run block 作为

module.run(['$templateCache', function($templateCache) {
$templateCache.put('components/directives/collapse.html',
'<div class="collapsible">\n' ...

但是,为什么我会收到 404 错误,例如

 GET http://localhost:3000/components/directives/collapse.html 404 (Not Found)

最佳答案

解决了。原因是 templateUrl 被赋予绝对路径(以“/”开头),但 templateCache 使用相对路径。因此从 templateUrls 中删除 '/' 解决了这个问题

关于javascript - Gulp Angular 构建模板缓存问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27615020/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com