【发布时间】:2023-03-08 03:20:01
【问题描述】:
我有一个使用 gulp 和 angular 的项目。我想单击一个按钮并弹出一个包含要显示的 html 的窗口。
在 build.js 文件中我有以下代码:
gulp.task('templates', function() {
gulp.src(['!./apps/' + app + '/index.html', './apps/' + app + '/**/*.html'])
.pipe(plugins.angularTemplatecache('templates.js', {
standalone: true,
module: 'templates'
}))
.pipe(gulp.dest(buildDir + '/js'));
});
在我的 app.js 文件中:
.controller('PopupCtrl', function($scope, ngDialog) {
$scope.clickToOpen = function () {
ngDialog.open({
template: 'templates/popup.html'
});
};
})
点击按钮时出现错误:
GET http://mylocalhost:3000/templates/popup.html 404 (Not Found)
我的 templates.js 文件包含:
angular.module("templates", []).run(["$templateCache", function($templateCache) {
$templateCache.put("templates/popup.html", "my html") ...etc
为什么模板缓存无法识别对 templates/popup.html 的调用并显示缓存中的内容而不是查看 404 的 URL?
只是说我尝试过的,我手动将模板文件复制到它正在查找的目录中并找到它。这不是解决方案,因为我希望它从缓存中获取。
谢谢
【问题讨论】:
标签: javascript angularjs caching gulp