angular.js - CORS error with AngularJS
黄舟
黄舟 2017-05-15 16:50:03
0
5
996

I am new to angularjs and used templateUrl when using the command. If I use this command directly, a Cross Origin Request Script (CORS) error will be reported on chrome. It may be due to security considerations and the file// file cannot be loaded directly. It should be possible under ff.

I would like to ask if there is a way to solve this problem under chrome without setting up a local server. Please give me some advice.

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(5)
Peter_Zhu

Precompile the template directly and cache it in $templateCache, so that the precompiled template can be loaded directly into the web page as a script without cross-domain problems. Automatic precompilation can be used during development (you can search for related solutions, such as grunt + ngTemplate, etc.).

If this is your first time coming into contact with the concept of precompiled templates, you may be confused. Don’t worry. At first, I checked a lot of information before I turned this corner and understood the principle. However, I am busy now and do not have time to explain it in detail. I suggest you first search for relevant information based on the five words precompiled template. I'll fill in the details when I have time.

曾经蜡笔没有小新

http://stackoverflow.com/questions/16251420/couldnt-load-template-using-templateurl-in-angularjs

我想大声告诉你

There is a Chrome plug-in. . . Google search cors chrome The first one is:)

给我你的怀抱

You can add the --disable-web-security parameter when opening chrome in a shortcut. . . Just right-click and change it in properties
Become "C:UsersAdministratorAppDataLocalGoogleChrome SxSApplicationchrome.exe" --disable-web-security
However, it will affect the normal use of chrome. You can use canary to do this.
Or, use grunt, use connect and add the livereload plug-in. Development is fun. connect is equivalent to making a server, and livereload can automatically update and refresh the browser

Ty80

It has been verified that everything mentioned above is acceptable. It just depends on which method you choose. Thank you everyone

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template