Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cant get $templateCache to work

Tags:

angularjs

Im using gulp-angular-templatecache to create a module with all my templates. This works fine and I get a module like this:

angular.module("starter.templates").run(["$templateCache",
  function($templateCache) {
    $templateCache.put("searchmachines.html",
        // searchmachines.html content
    );
    // etc.
  }
]);

But when I try to include this in my app I get this error:

Uncaught Error: [$injector:nomod] Module 'starter.templates' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument

In my index.html head I have this:

<head>
    /* other stuff */
    <script src="templates/templates.js"></script>
    <script src="js/app.js"></script>
    <script src="js/controllers.js"></script>
    <script src="js/services.js"></script>
    <script src="js/filters.js"></script>
</head>

and in my app.js I got this:

angular.module('starter', [
  'ionic',
  'starter.controllers',
  'starter.services',
  'starter.filters',
  'starter.templates'
])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
    window.location.href = '#/app/maincategories';
  });
})

.config(function($stateProvider, $urlRouterProvider) {
  $stateProvider

    .state('app', {
      url: "/app",
      abstract: true,
      templateUrl: "templates/menu.html",
      controller: 'AppCtrl'
    })

    .state('app.showmachine', {
      url: "/showmachine",
      views: {
        'menuContent' :{
          templateUrl: "templates/showmachine.html",
          controller: 'ShowMachinesCtrl'
        }
      }
    })
  //more routes...
  $urlRouterProvider.otherwise('/app/searchmachines');
});

What am I doing wrong?

like image 699
tobbe Avatar asked Apr 06 '14 10:04

tobbe


1 Answers

Problem was that, by default, gulp-angular-templatecache isnt making a standalone module. I totally missed that... By just passing the option: standalone:true everything works:

gulp.task('default', function () {
    gulp.src('./www/templates/**/*.html')
        .pipe(templateCache('templatescache.js', { module:'templatescache', standalone:true, root: './templates/' }))
        .pipe(gulp.dest('./www/templates/'));
}); 

and then in app.js just add the dependency:

angular.module('starter', [
  'ionic',
  'starter.controllers',
  'starter.services',
  'starter.filters',
  'templatescache'
])
like image 79
tobbe Avatar answered Sep 23 '22 07:09

tobbe