从文件加载HTML模板成AngularJs变量 [英] Load HTML template from file into a variable in AngularJs
问题描述
我与需要绑定的HTML富文本编辑器形式的工作。存储此HTML内容的最佳方式将是一个HTML文件。
I'm working with a form that needs to bind HTML to a Rich Text Editor. The best way to store this HTML content would be an HTML file.
我不能完全弄清楚如何从一个文件加载HTML模板,并将其分配给一个变量。
I can't quite figure out how to load an HTML template from a file and assign it to a variable.
指令似乎与templateUrl工作时要做到能够做到这一点。想知道,这没有在任何角度低水平API来实现控制器内的同样的事情。
Directives seem to do be able to do this when working with templateUrl. Was wondering if this there is any low level api in angular to achieve the same thing inside of a controller
推荐答案
所有模板都加载到缓存中。有一个注射 $ templateCache 服务,您可以用它来获得访问模板:
All templates are loaded into a cache. There is an injectable $templateCache service you can use to get access to the templates:
app.controller('testCtrl', function($scope, $templateCache){
var template = $templateCache.get('nameOfTemplate.html');
});
这篇关于从文件加载HTML模板成AngularJs变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!