角JS - 如何处理重复的HTML code像页眉/页脚? [英] Angular JS - How to handle duplicated HTML code like headers/footers?

查看:115
本文介绍了角JS - 如何处理重复的HTML code像页眉/页脚?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚阅读介绍角JS ,但我没有看到一个方法来code你的HTML头$什么C $ c和页脚code只有一次,并把它列入您的所有网页。

有没有做到这一点的官方/ reccomended方式?


解决方案

做官方的方法是使用的 ngInclude 指令,获取,编译和包括外部HTML片段。

\r
\r

< HTML NG-应用>\r
\r
< HEAD>\r
  &所述; SCRIPT SRC =HTTP://$c$c.angularjs.org/angular-1.0.1.min.js>&下; /脚本>\r
< /头>\r
\r
<身体GT;\r
  < D​​IV NG-包括SRC ='header.url'>< / DIV>\r
  ...\r
  < D​​IV NG-包括SRC ='footer.url'>< / DIV>\r
< /身体GT;\r
\r
< / HTML>

\r

\r
\r

有了这个,你可以重复使用相同 header.url footer.url 中的所有网页。

I just read the introduction to Angular JS but I didn't see anything about a way to code up your HTML header code and footer code just once and have it included in all of your pages.

Is there an official/reccomended way to do this?

解决方案

The official way to do it is to use ngInclude directive, which "fetches, compiles and includes an external HTML fragment".

<html ng-app>

<head>
  <script src="http://code.angularjs.org/angular-1.0.1.min.js"></script>
</head>

<body>
  <div ng-include src="'header.url'"></div>
  ...
  <div ng-include src="'footer.url'"></div>
</body>

</html>

With this you can reuse the same header.url and footer.url in all your pages.

这篇关于角JS - 如何处理重复的HTML code像页眉/页脚?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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