如何决定何时使用 ngView 或 ngInclude? [英] How to decide when to use ngView or ngInclude?

查看:18
本文介绍了如何决定何时使用 ngView 或 ngInclude?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想了解在 AngularJS 中使用 ngView 和 ngInclude 的方法的确切区别.什么时候使用一个而不是另一个是正确的?谢谢.

Just trying to understand the exact difference in approaches of using ngView and ngInclude in AngularJS. When would is it correct to use one over the other? Thanks.

推荐答案

ngView 与路由一起工作,并且对于 Angular SPA 至关重要.它通常用于包含您网站的主要内容,即每次用户单击链接时都会更改的页眉和页脚之间的部分.它与路由的集成意味着更改 ngView 内容也会更改控制器(取决于您的配置).

ngView works together with routing, and is mostly essential to an angular SPA. It's normally used to include the main content of your site, the bit in between the header and footer that changes every time a user clicks a link. Its integration with routing means changing the ngView content changes the controller too (depending on your configuration).

ngInclude 是一个通用的包含,你甚至可能不需要它.在多个视图需要包含相同代码的情况下,您有时会在视图中使用它以避免重复.

ngInclude is a general purpose include, you may not even need it. You'd sometimes use it inside a view to avoid repeating yourself, in the cases where several views need the same code included.

这篇关于如何决定何时使用 ngView 或 ngInclude?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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