AngularJs模板没有从$templateCache加载
AngularJs templates not loading from $templateCache
我目前正在构建一个Angular应用程序,需要通过script标签嵌入到任何其他网页上。
在使用resumeBootStrap
初始化应用程序之前,我决定使用一些JS来构建应用程序包装器,ng-view元素等。
然后我使用Grunt构建文件和Grunt -angular-templates来构建一个文件,然后从第三方网页调用。
所以,最初的dom构建等工作得很好,然而,我正试图从$templateCache
加载模板来加载我们添加到构建文件中的视图。我可以看到模板被添加到构建文件中,但是,当我尝试加载第三方页面时,我得到错误,因为它试图从本地服务器加载视图,而不是缓存/构建文件。
我的代码如下:
var app = angular.module('MyApp', [
'ngAnimate',
'ngCookies',
'ngResource',
'ngRoute',
'ngSanitize',
'ngTouch',
'ngScrollbar'
]);
app.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
})
});
angular.module('MyApp').run(['$templateCache', function($templateCache) {
'use strict';
$templateCache.put('views/main.html', '...')
...
任何关于如何做到这一点的建议非常感激,或者实际上,任何关于如何最好地包括我所有的视图等的提示,以便我不需要远程调用主机服务器来获取模板文件。
欢呼
Like:
$templateCache.put('views/main.html', $templateCache.get('views/main.html'))
templateCache美元https://docs.angularjs.org/api/ng/service/如果你使用grunt
https://github.com/karma-runner/karma-html2js-preprocessor你是否在html中包含grunt任务生成的js文件,即:
<script src="/templates.js"></script>
相关文章:
- 如何使用url加载程序在webpack中导入多个图像
- 如何在生成下载文件时显示加载动画
- 有没有任何方法可以将控制器从文件加载到ui路由器$stateProvider中
- 无法在通过jQuery的ajax加载的页面中执行javascript
- Emberjs应用程序加载在除Index之外的所有路由上
- 在chrome.tabs.onCreated之后加载HTML页面
- 单击F5时如何停止页面加载
- HTML5音频加载和播放获胜'我不能在iPad上工作
- 跟踪在页面加载时应用内联样式的JavaScript
- 在使用Polymer'加载所有json文件后执行方法;s的核心ajax
- jQuery Lazy加载动画滚动
- Html页面上的多个Base64图像和平滑加载
- 如何创建带有插槽的vue js组件预加载程序
- Webpack/Rect:遵循egghead.io教程,但出现错误:您可能需要一个合适的加载程序来处理此文件类型
- 如何使该数据在所有元素中加载
- Chrome扩展没有't在重新加载之前考虑期权价值
- 使用javascript在Flash中加载外部图像
- Angular js使用模板url将模板加载到templateCache中
- AngularJs模板没有从$templateCache加载
- $templateCache是否支持图像预加载?