Tutorialsplane

AngularJs ng-include based on Condition


AngularJs ng-include based on Condition: Sometimes we need to include another html page(template) based on some condition. You can use ng-if to include another page on the based of some condition. Here in this tutorial we are going to explain how you can Add condition while including another page. You can also use our online editor to edit and run the code online.


AngularJs ng-include based on Condition Example

If you want to include another page using ng-include and you want to include that template only when some condition is met. Let us create an example to add if condition to load another Html page-

AngularJs ng-include Example Based on Condition:

<div ng-if="someCondition" ng-include="'anotherpage.Html'"></div>

In the above example the template will be included only when ng-if condition is satisfied.