3

I have a index.html file and another topBar.html file and I want to include that file in my index.html.

My directory structure is like below:

mainfolder/
    scripts/
    views/
        topBar.html
    index.html

Here is the code that I tried

 <div ng-controller="mainCtrl">
   <div ng-include="'views/topBar.html'"></div>
 </div>

But nothing is being displayed and it gives me error in the console

angular.js:12701 Failed to load file:'path' Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

2

1 Answer 1

3

If you have written your code in yur code editior and testing your page in your browser without using any server then this error comes. You can test plain html css in browser that will work fine , but when you craete something more than just html , css then that gives error . A server has to be used for that .many web browsers are programed to watch for cross site attacks, and will block requests. You don't want anyone being able to read your hard drive from your web browser.

Solution :

Install a local server and then run your application on server.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.