Kunal Vashist
Kunal Vashist

Reputation: 2471

Angular Ng-if vs Ng-include

Which is better to use on route views

obj = { contact:true,about:false };
<div ui-view="contact" ng-if="obj.contact"></div>
<div ui-view="about" ng-if="obj.about"></div>

or

<div ui-view="contact" ng-include="obj.contact"></div>
<div ui-view="about" ng-include="obj.about"></div>

Both do the same work bring template on the main html.

Among them which one is better to use for this case and why?

Upvotes: 2

Views: 1027

Answers (2)

ilcorvo
ilcorvo

Reputation: 486

ng-include has a significant performance hit.

Look at this: Avoiding ng-include for Elegance and Performance

Upvotes: 0

Hacknightly
Hacknightly

Reputation: 5164

ng-include is used to include an external HTML template, not to conditionally hide/show content. In this case, ng-if is correct.

https://docs.angularjs.org/api/ng/directive/ngInclude

Upvotes: 3

Related Questions