ng-include compiles to a comment

All we need is an easy explanation of the problem, so here it is.

I have an angular app, and want to in a template, add other as divs. ng-include seemed like a perfect choice.

In main.html

<div id="page-wrapper">
<div ng-include src="'/partials/module.html'"></div>

In module.html

<div class="module">

All files live in the partials-folder in the app.

When running this, at the place in the html code, I get <!-- ngInclude: -->, and substituting the divs in main.html with the also supported ng-include tag, it compiles to <!-- ngInclude: undefined -->.

Does anyone know what might be the problem?

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

You only use src=”” when using ng-include as an element:

<ng-include src="'/partial.html'"></ng-include>

When using ng-include as an attribute, you put the partial URL right in the attribute itself:

<div ng-include="'/partial.html'"></div>

See for the two use-cases.

Method 2

After hours I resolved it for mine, it’s all about using single quotes using between double quotes.

<!--it will not work-->
<ng-include src="views/header.html"></ng-include>

<!--it will work :)-->
<!--Difference is single quotes along with double quotes around src string-->
<ng-include src="'views/header.html'"></ng-include>

Method 3

I was facing the exact issue, compiler might not be finding the src path you provided.
remove the first / in the path. compiler will automatically append / to the root context and tries to find the path. It worked for me.

<div ng-include src="'/partials/module.html'"></div> 

replace with

<div ng-include src="'partials/module.html'"></div>

Method 4

I got stuck in the same issue, none of the solutions mentioned above helped me out to solve the problem and it ate my two whole days. Finally I figured out with the help of this link.

Also the solution to make this work requires below two traits:

  1. partial html should be included in single quotes
  2. secondly full path of the file needs to be mentioned even if the file is present in the same location.


---- DEF
      --- abc.html
      --- partial.html

So if abc.html has ng-include syntax then it should be like as below

<div ng-include="'ABC/DEF/partial.html'"></div>
<ng-include src="'ABC/DEF/partial.html'"></ng-include>

Method 5

It must be a scope issue. Make sure the $scope object is passed properly and do not forget to include the controllers and services pertaining to the partial in your main page!

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply