I want to create separate template files to keep my HTML clean and modular. Angular is unable to pull in local files for usage as a template.
For example I have a file at src/views/test.html
, and my src/js/main.js
looks like:
var app = angular.module('test', [
'ngRoute',
'ngTouch'
]);
app.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/', {
controller: 'TestController',
templateURL: 'views/test.html'
$routeProvider.otherwise({
redirectTo: '/'
});
}]);
app.controller('TestController', function($scope, $routeParams) {});
But the app doesn't work and the template HTML is not pulled in.
I tried playing around with forge.file.getLocal
and forge.file.string
but the seem incompatible with template
option of $routeProvider.when
because they are asynchronous.
It turns out the problem was that I was a capitalization problem. You MUST use templateUrl
, not templateURL
, for the Angular JS router to work.