【发布时间】:2015-05-17 02:41:55
【问题描述】:
我不明白为什么我的 $templateCache 设置不起作用...
见this plnkr。我将它与new Angular router 一起使用,我在$templateCache 中有我的home 组件模板。 app.js 文件如下所示:
var app = angular.module('app', ['ngNewRouter','app.home']);
app.run(['$templateCache', function($templateCache) {
$templateCache.put('components/home/home.html', '<h2>The home page</h2>{{home.test}}');
}]);
app.controller('AppController', ['$router','$templateCache', AppController]);
function AppController($router,$templateCache) {
var vm = this;
console.log("The template looks like this:",$templateCache.get('components/home/home.html'));
$router.config([{
path: '/',
component: 'home'
}]);
}
我的 components/home/home.js 文件:
angular.module('app.home', [])
.controller('HomeController', [HomeController]);
function HomeController() {
var vm = this;
vm.test = "String from the home controller";
}
我得到的错误信息是:
http://run.plnkr.co/OFd5k46BCkBdnfkK/components/home/home.html 404 (Not Found)
有什么想法吗?
【问题讨论】:
-
请注意,您在缓存中将其注册为相对 URL,而不是绝对 URL。
-
是的,如我所愿。出于某种原因,我应该将其注册为绝对网址吗?
标签: angularjs