2014-12-23 3 views
0

$ inject 주석을 내 Typescript 클래스에서 작동 시키려고하는데 항상 정의되지 않은 것 같습니다. 누구든지 내가 뭘 잘못하고 있다고 제안 할 수 있습니까? 그것은 작동

app.controller('AuthenticationControl', [ '$window', Picasa.PicasaAuthenticator ]); 

을 : 나는 $의 분사 주석을 제거하고이에 내 컨트롤러 생성을 변경하는 경우

export class PicasaAuthenticator { 

    static $inject = [ '$window' ]; 
    constructor(private $window : ng.IWindowService) 
    { 
    } 

    public startAuthentication() 
    { 
     var authUrl:string = "https://accounts.google.com/o/oauth2/auth"; 
     authUrl += "?client_id=" + client_id; 
     authUrl += "&response_type=token"; 
     authUrl += "&scope=https://picasaweb.google.com/data/"; 
     authUrl += "&redirect_uri=" + window.location; 

     if (this.$window) 
     { 
      this.$window.location.assign(authUrl); 
     } 
     else 
     { 
      alert("nav: " + authUrl); 
     } 
    } 
} 

app.controller('AuthenticationControl', [ Picasa.PicasaAuthenticator ]); 

.

많은 감사 당신의 사용과 정적 $inject 속성에 제공 사출 인수를 무시되기 때문이다

답변

3

을 (내가 PicasaAuthenticator 아마 단일해야하며, 서비스로 정의 될 것을 알고) 서비스를 등록 할 때 표기법을 다시 사용하십시오. 대괄호 표기법을 사용하면 대체 구문으로 명시 적 종속성 주석을 지정하며 사용자의 경우에는 주입 인수를 나열하지 않습니다. 따라서 각도 DI 프로세스로 주입되는 것을 보지 못합니다.

app.controller('AuthenticationControl', [ Picasa.PicasaAuthenticator ]); 
             // ^__ Remove this 

그냥 할 : -

app.controller('AuthenticationControl', Picasa.PicasaAuthenticator); 
+0

아하! 나는 많이 깔끔한 것을 본다! 그래서 원래의 버전에서 Inject 배열은 컨트롤러에서 다시 정의했을 때 무시되었습니다. 많은 감사. – Roaders

+0

@Roaders 예 맞습니다 .. 당신은 .. 오신 것을 환영합니다 .. :) – PSL

관련 문제