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