我正试图从AngularJS调用WebAPI.这是一个简单的GET请求,我在服务器上启用了CORS.
我收到$ injector:unpr未知提供程序错误.
我有一个名为raterModule.js的角度模块:
var raterModule = angular.module('rater', []);
Run Code Online (Sandbox Code Playgroud)
一个名为corsService.js的服务,它使用了enable-cors.org中的代码段:
raterModule.factory("corsService",
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
// Check if the XMLHttpRequest object has a "withCredentials" property.
// "withCredentials" only exists on XMLHTTPRequest2 objects.
if ("withCredentials" in xhr) {
xhr.withCredentials = true;
xhr.open(method, url, true);
}
// Otherwise, check if XDomainRequest. XDomainRequest only exists in IE, and is IE's way of making CORS requests.
else if (typeof XDomainRequest != …Run Code Online (Sandbox Code Playgroud)