I read the tutorial on Angular. I go on "try it now". Here is one of the examples. Everything works fine. I save to my folder: index.html main.htm - copy london.html london.htm paris.htm

I start - I get an error. In addition, in index.html I had to fix the link in the head

error: XMLHttpRequest cannot load file: /// D: /Docs/angular/main.htm. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

angular.js: 12520 Error: [$ compile: tpload]

what am i doing wrong I would save the example locally and run it in the browser and continue to experiment on your own.

  • one
    this is intended, it is necessary to run on a local server, when started as a regular file (using the file:/// protocol) - ajax requests do not work, and all the loadings of the templates are made by them. - Grundy
  • XMLHttpRequest does not work locally, in order to play with this you need a server - Sasha Omelchenko
  • @Grundy is understandable, can be issued as an answer - kvvk

1 answer 1

Applications using Angular are not designed to run on a local server, since loading templates from a separate file is done with a regular ajax request.

At the same time, if you simply open the html file in the browser, the file:/// protocol for which ajax requests are prohibited is used, because of this, an error occurs when loading the template and the entire application crashes.

As a workaround, you can use the option to place templates in script tags with type="text/ng-template" .

Thus, an example can be made to work by transferring all templates to the main file into script tags and assigning to them the id corresponding to the requested addresses, for example:

 <script type="text/ng-template" id="path/to/template">...</script>