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.
How to decide when to use ngView or ngInclude?
Asked Answered
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 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.
Cool. Does ngInclude create its own scope or does it inherit the scope of the HTML it is embedded within? If so, doesn't that make re-use hard since the scope variables referenced inside the ngInclude HTML would need to be named the same in all parent HTMLs that want to use it? –
Riebling
ng-include creates indeed a new child scope –
Pug
© 2022 - 2024 — McMap. All rights reserved.
ng-include
anywhere including nesting in templates.ng-view
managed by routing so typically only one exists – Gelasius