Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decide when to use ngView or 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.

like image 682
Breako Breako Avatar asked Nov 16 '13 23:11

Breako Breako


People also ask

What is the use of ngView directive?

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.

Which of the following is the correct way to include the NG view directive in your application?

Answer: C is the correct option. The ng-bind directive is used to bind the application data to the HTML view in the AngularJS application.

Which of the following essential argument is required while using Ng include directive in angular?

AngularJS ng-include Directive 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 $viewContentLoaded?

$viewContentLoaded is fired as soon as the ui-view has the template compiled, and the controller has been executed. The dom may change at the next $digest in response to something that happened in the controller, or whatever.


1 Answers

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.

like image 147
Michael Low Avatar answered Oct 01 '22 12:10

Michael Low