I have used recently the ng-view in partial view and it looks much like the use of ng-include. Is there a difference between the two: ng-view directive and ng-include or when is it better to use which?
The ng-include directive includes HTML from an external file. The included content will be included as childnodes of the specified element. The value of the ng-include attribute can also be an expression, returning a filename. By default, the included file must be located on the same domain as the document.
ngView is a directive that complements the $route service by including the rendered template of the current route into the main layout ( index. html ) file. Every time the current route changes, the included view changes with it according to the configuration of the $route service.
The primary purpose of the ng-include directive is used to fetch, compile, and include an external HTML file in the main AngularJS application. These are added as child nodes in the main application. The ng-include attribute's value can also be an expression, that returns a filename.
ngInclude creates a new child scope which inherits scope values from the parent controller.
Basicly ng-View creates a new View which works with States or Routing, saying this view gets his own Controller and Stuff like it would be a html file. And ng-include is if you have like a html template which u need to show on different views and include it to not duplicate code.
So for example you can ng-include your header html where you have your navigation, and you could ng-view a register form or smth where you need it to have its own Route/ State and Controller
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With