javascript 如何决定何时使用 ngView 或 ngInclude?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20025101/
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
How to decide when to use ngView or ngInclude?
提问by Breako Breako
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.
只是想了解在 AngularJS 中使用 ngView 和 ngInclude 的方法的确切区别。什么时候使用一个而不是另一个是正确的?谢谢。
采纳答案by mikel
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).
ngView 与路由一起工作,并且对于角度 SPA 至关重要。它通常用于包含您网站的主要内容,即每次用户单击链接时页眉和页脚之间的部分。它与路由的集成意味着更改 ngView 内容也会更改控制器(取决于您的配置)。
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.
ngInclude 是一个通用的包含,你甚至可能不需要它。在多个视图需要包含相同代码的情况下,有时您会在视图中使用它以避免重复。