angular.js - AngularJS的CORS错误
黄舟
黄舟 2017-05-15 16:50:03
0
5
980

初学angularjs,在使用指令的时候用到了templateUrl,直接使用该指令的话在chrome上是会报Cross Origin Request Script(CORS)错误,可能是基于安全考虑吧,不能直接加载file//文件。在ff下应该是可以的。

想问一下,在chrome下,有没有方式不通过搭建一个本地的服务器来解决这个问题,请各位大牛指教。

黄舟
黄舟

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

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