Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ';未定义';将附加到特定的Web API调用_Javascript_Angularjs_Asp.net Web Api2 - Fatal编程技术网

Javascript ';未定义';将附加到特定的Web API调用

Javascript ';未定义';将附加到特定的Web API调用,javascript,angularjs,asp.net-web-api2,Javascript,Angularjs,Asp.net Web Api2,“Undefined”被附加到我的angular应用程序中的特定WebAPI调用中,在该应用程序中,其他调用成功而没有问题 由于“未定义”字符,registerUser和login调用均失败: 请求URL: 请求URL: 这是我的密码: (function () { "use strict"; angular .module("userManagement") .controller("mainCtrl", ["userAccount",

“Undefined”被附加到我的angular应用程序中的特定WebAPI调用中,在该应用程序中,其他调用成功而没有问题

由于“未定义”字符,registerUser和login调用均失败:

请求URL:

请求URL:

这是我的密码:

    (function () {
    "use strict";
    angular
        .module("userManagement")
        .controller("mainCtrl", ["userAccount", mainCtrl])

    function mainCtrl(userAccount) {
        var vm = this;
        vm.isLoggedIn = false;
        vm.message = '';
        vm.userData = {
            userName: '',
            email: '',
            password: '',
            confirmPassword: ''
        };

        vm.registerUser = function () {
            vm.userData.confirmPassword = vm.userData.password;
            userAccount.registration.registerUser(vm.userData, function (data) {
                vm.confirmPassword = "";
                vm.message = "...Registration successful";
                // vm.login();
            });
        }
        vm.login = function () {
            vm.userData.grant_type = "password";
            vm.userData.userName = vm.userData.email;
            userAccount.login.loginUser(vm.userData, function (data) {
                vm.isLoggedIn = true;
                vm.password = "";
                vm.message = "";
                vm.token = data.access_token;
            });
        }
    }
}());
以下是userAccount工厂方法中的代码:

 (function () {
    "use strict";
    angular.module("common.services")
    .factory("userAccount", ["$resource", "appsettings", userAccount])
    function userAccount($resource, appsettings) {
        return {
            registration: $resource(appsettings.serverPath + "/api/Account/Register", null,
                {
                    'registerUser': { method: 'POST' }
                }),
            login: $resource(appsettings.serverPath + "/Token", null,
                {
                    'loginUser': {
                        method: 'POST',
                        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                        transformRequest: function (data, headersGetter) {
                        var str = [];
                        for (var d in data) {
                            str.push(encodeURIComponent(d) + "=" + encodeURIComponent(data[d]));
                            return str.join("&")
                        }
                    }
                }
            })
        }
    }

})();
Appsettings的定义如下:

(function () {
   "use strict";
    angular.module("common.services", ["ngResource"]).constant("appsettings", {
        serverpath:"http://localhost:25879/"
    });
}());

我是Angular和WebAPI的新手,如果您有任何帮助或指导,我们将不胜感激

apiSettings
中检查
serverPath
apiSettings
中检查
serverPath
您的
appsettings
常量应该如下所示:

(function (angular) {
   "use strict";
    angular.module("common.services", ["ngResource"]).constant("appsettings", {
        serverPath: "http://localhost:25879"
    });
}(angular));

属性
serverpath
serverpath
不同,在您的情况下
serverpath
未定义的。你应该尊重外壳

您的
appsettings
常量应该如下所示:

(function (angular) {
   "use strict";
    angular.module("common.services", ["ngResource"]).constant("appsettings", {
        serverPath: "http://localhost:25879"
    });
}(angular));

属性
serverpath
serverpath
不同,在您的情况下
serverpath
未定义的。你应该尊重外壳

您能给我们看一下您的
appsettings
吗?没有为这些调用设置appsettings.serverPath。请检查控制台日志(函数(){/“use strict”;angular.module(“common.services”,[“ngResource”]).constant(“appsettings”,{serverpath:});}())@MujeebuRahman控制台日志无错误,已将问题更新为appsettings code.appsettings.serverPath替换为appsettings.serverPath是否也可以显示您的
appsettings
?appsettings.serverPath未为这些调用设置。请检查控制台日志(函数(){/“use strict”;angular.module(“common.services”,[“ngResource”]).constant(“appsettings”,{serverpath:});}())@MujeebuRahman控制台日志上无错误,已使用appsettings代码更新问题。appsettings.serverPath替换为appsettings.serverPath我已使用应用程序设置文件更新问题。有什么特别的我应该检查的吗?打字错误。serverpath不等于serverpath。检查是否已使用应用程序设置文件更新问题。有什么特别的我应该检查的吗?打字错误。serverpath不等于serverpath。检查肠衣鱼是不是太笨了!:|感觉好笨|