質問

I have a problem with the external function OnLoginFail when invoking the function showFormAndHideMessage from it. I try using

 angular.element($("login")).scope().showFormAndHideMessage().$digest(); 

but it doesn't not work. I understand that scope() should give me access to controller in directive.

Login.js

  lobby.directive( 'login', function() {
    return {
    restrict: 'E',
    replace: false,
    templateUrl: 'lobby/login/login.html',
    scope: {},

         ....

    function OnLoginFail( error ) {
       alert( error.Message );
       angular.element($("login")).scope().showFormAndHideMessage().$digest();  

   }
役に立ちましたか?

解決

Scope only gives you direct access to parent scope if you aren't creating an isolate scope in your directive. You are isolating your scope in your directive with the following line:

scope: {}

EDIT

Per JPRO's comment, to fix this just delete that line in your directive's configuration.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top