2014-10-22 1 views
0

희망 사항 나는 기존의 질문을 복제하지 않고 있습니다 ... 내 서비스에서 "this"에 연결된 함수에 액세스하려고합니다.하지만 내부에서이 작업을 수행해야합니다. jQuery의 이벤트 바인딩jquery 코드 내의 각도 범위에 접근하기

하지만 각도에서 "정의되지 않은 함수가 아닙니다"라는 오류가 발생합니다.

코드 :

app.service("whatever",function(){ 

this.instantiatePreIds = function() { 
    /**whatever code**/ 
} 

this.checkOnLoad = function() { 

    angular.element(window).bind("popstate", function (e) { 

     this.instantiatePreIds(); /***this row throws that error***/ 

    }); 
} 
}); 

어떤 제안이? 감사.

답변

0

알았어. 알았어! 내가 할 일은 범위에 대한 참조를 var에 넣고 대신 사용하는 것뿐입니다.

/*inside the service*/ 

var ref=this; 

this.checkOnLoad = function() { 

    angular.element(window).bind("popstate", function (e) { 

     ref.instantiatePreIds(); 

    }); 
} 

yesss!

관련 문제