我有一个使用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?只是想说我已经尝试过了,我手动将模板文件复制到它所在的目录中,它找到了。但这并不是解决办法,因为我希望它从缓存中取出。谢谢。