如何使用gulp-angular-templatecache缓存$ routeProvider templateUrl

时间:2015-06-12 23:06:09

标签: angularjs caching gulp

我有以下代码来缓存模板。我正在使用gulp预缓存模板。但是我无法将它用于路由器URL。

'use strict';

var config         = require('../config');
var gulp           = require('gulp');
var templateCache  = require('gulp-angular-templatecache');

// Views task
gulp.task('views', function() {

// Put our index.html in the dist folder
gulp.src('app/**/*.html')
.pipe(gulp.dest(config.dist.root));

// Process any other view files from app/views
return gulp.src(config.views.src)
.pipe(templateCache({
  standalone: true
}))
.pipe(gulp.dest(config.views.dest));

});

//in router
app.config(function($routeProvider) {

 $routeProvider.when('/todos', {
  templateUrl: 'views/todos.html',
  controller: 'TodoCtrl',
 });
});

有人可以帮助我如何在此路由器中使用缓存模板吗?

1 个答案:

答案 0 :(得分:0)

我遇到了这个问题。虽然模板缓存我们必须有五个模板的实际路径,否则它将采用相对URL。如果您的模板位于视图目录中,那么我们必须像这样更新它...

templateCache({
  root:'views', 
  standalone: false
}) 
相关问题