Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not sure when to use ng-view or ng-include

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?

like image 319
Taiwotman Avatar asked Aug 27 '15 12:08

Taiwotman


People also ask

What is the use of NG-include?

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.

What is the use of NG view?

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.

Why we use ng-include in AngularJS?

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.

Does Ng-include create a new scope?

ngInclude creates a new child scope which inherits scope values from the parent controller.


1 Answers

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

like image 119
stackg91 Avatar answered Oct 23 '22 03:10

stackg91