AngularJS中的模板类似于Handlebars? [英] Resolve template in AngularJS similar to Handlebars?
本文介绍了AngularJS中的模板类似于Handlebars?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< script type =text / ng- templateid =mytemplate>
名称是{{name}}
< / script>
我可以使用$ templateCache.get('mytemplate')获取模板,但是如何解决该模板一个可以插入DOM的有效HTML。
例如:
var html = $ templateCache.get('mytemplate',{name:'Ace'});
应输出Name is Ace
解决方案
免责声明:我没有试过这个,但我认为它会起作用。
var scope = $ rootScope。$ new();
scope.name ='Ace';
var html = $ compile($ templateCache.get('myTemplate'))(scope);
基本上,创建一个范围,在其上设置值,然后将其传递到编译模板中。 p>
How to resolve an AngularJS template with a syntax similar to Handlebar?
<script type="text/ng-template" id="mytemplate">
Name is {{name}}
</script>
I can get the template using $templateCache.get('mytemplate') buthow to resolve that template to a valid HTML that can be inserted into DOM.
For example:
var html = $templateCache.get('mytemplate', {name: 'Ace' });
should output "Name is Ace"
解决方案
Disclaimer: I haven't tried this, but I think it will work.
var scope = $rootScope.$new();
scope.name = 'Ace';
var html = $compile($templateCache.get('myTemplate'))(scope);
Basically, create a Scope, set values on it and then pass it into a compiled template.
这篇关于AngularJS中的模板类似于Handlebars?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文