C# 角度服务功能未定义-MVC6
我正在尝试编写一个登录服务(用typescript),它将用户名和密码发布到我的C#controller。然后,C#控制器发出一个服务调用,点击我的数据库对用户进行身份验证,但这超出了这个问题的范围 问题是,当我尝试从angular controller调用身份验证函数(在angular服务中找到)时,我在控制台中收到一个错误,即C# 角度服务功能未定义-MVC6,c#,angularjs,typescript,asp.net-core-mvc,angular-services,C#,Angularjs,Typescript,Asp.net Core Mvc,Angular Services,我正在尝试编写一个登录服务(用typescript),它将用户名和密码发布到我的C#controller。然后,C#控制器发出一个服务调用,点击我的数据库对用户进行身份验证,但这超出了这个问题的范围 问题是,当我尝试从angular controller调用身份验证函数(在angular服务中找到)时,我在控制台中收到一个错误,即无法获取未定义或空引用的属性“Authenticate”。 以下是我的服务的基类(处理程序): module app.Services { export class H
无法获取未定义或空引用的属性“Authenticate”。
以下是我的服务的基类(处理程序):
module app.Services {
export class HttpHandlerService {
httpService: ng.IHttpService;
handlerUrl: string;
constructor($http: ng.IHttpService) {
super();
this.httpService = $http;
}
useGetHandler(params: any): ng.IPromise<any> {
var result: ng.IPromise<any> = this.httpService.get(this.handlerUrl, params)
.then((response: any): ng.IPromise<any> => this.handlerResponded(response, params));
return result;
}
usePostHandler(params: any): ng.IPromise<any> {
var result: ng.IPromise<any> = this.httpService.post(this.handlerUrl, params)
.then((response: any): ng.IPromise<any> => this.handlerResponded(response, params));
return result;
}
handlerResponded(response: any, params: any): any {
response.data.requestParams = params;
return response.data;
}
}
}
最后是我的c#controller“
我确实得到了一个错误,只是在IE中,
\u super
是未定义的。无法获取未定义或空引用的属性“Authenticate”。
意味着此.loginService
不是由Angular正确注入的
您可以尝试更改此选项:
static$inject=[“$state”];
为此:
static$inject=[“$state”,“LoginService”];
确切的错误消息是什么?身份验证函数未定义或loginService属性未定义?
无法获取未定义或空引用的属性“Authenticate”。
实际上,它似乎没有更新JS。现在,我收到一个未知提供程序:LoginServiceProvider
错误,这可能是只是缺少一个参考
module app.Services {
export interface ILoginService {
Authenticate(email: string, password: string): ng.IPromise<any>;
}
export class LoginService extends Services.HttpHandlerService {
static $inject = ['$http'];
constructor($http: ng.IHttpService) {
this.handlerUrl = '/Login';
super($http);
}
// Authentication function I am attempting to call
Authenticate(email: string, password: string): ng.IPromise<any> {
// I have not completed the actual request that is being sent
var config: any = {};
var request = {
"Email": email,
"Password": password
}
return this.usePostHandler(config);
}
}
angular.module('App').factory('loginService', LoginService);
}
module app.Login {
import Services = app.Services;
interface ILoginController {
email: string;
password: string;
login(): void;
}
class LoginController implements ILoginController{
email: string;
password: string;
loginService: Services.ILoginService;
loginForm: any;
static $inject = ["$state"];
constructor(private $state: ng.ui.IStateParamsService, loginService: Services.ILoginService) {
this.email = "";
this.password = "";
this.loginService = loginService;
}
login() {
if (this.loginForm.$invalid) {
return;
}
var request = this.loginService.Authenticate(this.email, this.password);
request.success(function (data) {
console.log("User authenticated.");
});
request.error(function () {
console.log("Error: User not authenticated.");
});
}
}
angular.module('App').controller('loginController', LoginController);
}
[HttpPost]
[Route("/Login")]
public async Task<IActionResult> Login()
{
// . . . .
}
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var app;
(function (app) {
var Services;
(function (Services) {
var LoginService = (function (_super) {
__extends(LoginService, _super);
function LoginService($http) {
this.handlerUrl = '/Login';
_super.call(this, $http);
}
LoginService.prototype.Authenticate = function (email, password) {
var config = {};
var request = {
"Email": email,
"Password": password
};
return this.usePostHandler(config);
};
LoginService.$inject = ['$http'];
return LoginService;
})(Services.HttpHandlerService);
Services.LoginService = LoginService;
angular.module('App').factory('loginService', LoginService);
})(Services = app.Services || (app.Services = {}));
})(app || (app = {}));