angularjsangularjs-ng-include

Error Occuring while including html file using ng-include


I got following error while including html file using ng-include.

XMLHttpRequest cannot load file:///home/algo/Dnyaneshwar/Angular/TestProject/views/header1.html. 
Cross origin requests are only supported for protocol schemes: 
http, data, chrome, chrome-extension, https, chrome-extension-resource.

Solution

  • Cause of Issue
    This error is happening because you are just trying to open your html documents directly from the browser. Since you are using either file:// or C:/, thats why the error is saying that they are not http:// or https:// .
    Don't try to run it through folder directly.

    How to fix it
    You need to access your code through a webserver and access it on localhost. If you have eclipse or apache setup, use it to access your files. Some IDE's like intellij,eclipse have built in web servers.

    If you have node setup then Just run npm install http-server -g and you will be able to use it in terminal like http-server C:\path\to\app

    See Also