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.
天蓬老师2017-05-15 16:52:03
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.
曾经蜡笔没有小新2017-05-15 16:52:03
http://stackoverflow.com/questions/16251420/couldnt-load-template-using-templateurl-in-angularjs
我想大声告诉你2017-05-15 16:52:03
There is a Chrome plug-in. . . Google search cors chrome
The first one is:)
给我你的怀抱2017-05-15 16:52:03
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
PHP中文网2017-05-15 16:52:03
It has been verified that everything mentioned above is acceptable. It just depends on which method you choose. Thank you everyone