问题
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"
回答1:
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.
来源:https://stackoverflow.com/questions/25203125/resolve-template-in-angularjs-similar-to-handlebars