将文件中的 HTML 模板加载到 AngularJs 中的变量中 [英] Load HTML template from file into a variable in AngularJs

查看:26
本文介绍了将文件中的 HTML 模板加载到 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆