我正在尝试在 AngularStrap 弹出窗口中加载模板文件,但是我在使用 $templateCache 时遇到了问题。我似乎比其他 SO 问题更退一步,因此这似乎是双重问题。
在 API 文档之后,我在结束标记<script type="text/ng-template" id="popoverTemplate.html"></script>
之前添加了一个。</body>
当我<div ng-include="'popoverTemplate.html'"></div>
在我的页面上使用时,我什么也得不到。如果我尝试使用console.log($templateCache.get("popoverTemplate.html"))
我得到“$templateCache is not defined”,这导致我假设我错过了一个关键步骤。但是,我在文档或其他 SO 问题中找不到如何操作。
编辑:注入服务是缺少的链接。但是,当我注入服务时,控制器的其他功能不再起作用,但是如果您注入所有函数的参数,则工作代码将变为:
(function() {
"use strict";
angular.module("app").controller("managerController", ["$scope", "imageHierarchyRepository", "$templateCache", function ($scope, imageHierarchyRepository, $templateCache) {
imageHierarchyRepository.query(function(data) {
$scope.hierarchies = data;
});
var template = $templateCache.get("popoverTemplate.html");
console.log(template);
}]);
})();