2016-04-07 17 views
0

Kullanıcı adı ve parolamı C# denetleyicime gönderen bir giriş hizmeti (yazı tipinde) yazmaya çalışıyorum. C# controller daha sonra, kullanıcı kimliğini doğrulamak için veritabanına isabet eden bir servis çağrısı yapar, ancak bu sorunun kapsamı dışındadır.Açısal hizmet işlevi tanımsız - MVC6

konu benim açısal denetleyicisinden (benim açısal hizmetinde bulunursa) benim kimlik doğrulama işlevini çağırmak çalıştığınızda, ben burada unable to get property 'Authenticate' of undefined or null reference.

benim konsolunda bir hata taban sınıftır elde ediyoruz benim hizmetleri için (Handler):

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; 
    } 

} 
} 

Sonra giriş hizmeti bunu devralır: Burada

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); 
} 

Ben benim giriş kontrolörü olan

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); 
} 

Ve nihayet benim C# denetleyicisi"

[HttpPost] 
[Route("/Login")] 
public async Task<IActionResult> Login() 
{ 
    // . . . . 
} 

Herhangi bir yardım mutluluk duyacağız: servisini arayarak. Daha fazla bilgiye ihtiyacın olursa haberim olsun.

DÜZENLEME:

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 = {})); 

Ben _super tanımsız olduğunu, sadece IE, bir hata alıyorum yapın:

Bu oturum açma hizmeti yazılardan oluşturulan javascript.

+0

tam hata mesajı nedir? Bu Kimlik Doğrulama işlevi tanımsız veya loginService özelliği tanımsız mı? – goenning

+0

'Özellik undefined veya null referansı 'Authenticate' özelliği alınamıyor. ' – cfly24

cevap

0

Unable to get property 'Authenticate' of undefined or null reference.this.loginService düzgün açısal enjekte olmayan anlamına gelir.

Sen değiştirmeyi deneyebilirsiniz bu: Buna

static $inject = ["$state"];

:

static $inject = ["$state", "LoginService"];

Proper Dependency Injection in Your AngularJS TypeScript Apps

+0

Ne yazık ki, bu – cfly24

+0

hatasını çözmedi Aslında, JS'yi güncelleştirmediği anlaşılıyor. Şimdi, ben sadece bir eksik başvuru – cfly24

+0

eksik bir referans oldu, tüm iyi bilinmeyen bir sağlayıcı: LoginServiceProvider 'hata alıyorum! – cfly24