javascript 如何使用 Angular JS 作为模板引擎?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14072192/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 20:37:48  来源:igfitidea点击:

How do I use Angular JS as a templating engine?

javascripthtmlangularjs

提问by Dan Kanze

This postgoes into detail how to bind loading template partials on events.

这篇文章详细介绍了如何在事件上绑定加载模板部分。

But what if I wanted to load template partials on page loadsimilair to a templating engine like Smarty?

但是,如果我想在页面加载时加载模板部分,类似于 Smarty 这样的模板引擎怎么办?

For example in Smarty:

例如在 Smarty 中:

<html>
<body>
{include file="templates/header.html"}
<span>Dude, this has too be possible in Angular JS...</span>
{include file="templates/footer.html"}
</body>
</html>

回答by Wouter

You can use the ngInclude directive. The documentation and an example can be found here: http://docs.angularjs.org/api/ng.directive:ngInclude

您可以使用 ngInclude 指令。可以在此处找到文档和示例:http: //docs.angularjs.org/api/ng.directive: ngInclude