小编Ven*_*ris的帖子

AngularJS喷油器问题

我正试图从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)

javascript asp.net-web-api angularjs angularjs-injector

5
推荐指数
1
解决办法
270
查看次数