2014-09-11 2 views
0

draw2d 라이브러리는 초기화 될 때 dom을 가로 지르고 마술을 실행합니다.각도, 두 개의 지시문이로드되고 다른 외부 라이브러리가 시작될 때까지 기다립니다.

모든 것이로드 된 후에 트릭이 시작됩니다.

draw2d 라이브러리가 작동하는 데 필요한 몇 가지 추가 클래스가있는 각도 js 지시문 인 메뉴와 캔버스를 제어합니다.

angular.module('test').directive('load-menu', function() { 
console.log('i am the menu for the draw2d library'); 
}); 

angular.module('test').directive('the-canvas', function() { 
console.log('i am the canvas for the draw2d library'); 
}); 

지금 알고 나를 수있는 방법은로드와 draw2d 라이브러리를 인스턴스화 할 때, 두 지시어를 보유 컨트롤러, 내부에서,있다?

angular.module('test').controller('areTheDirectivesLoaded', function() { 
    // are the directives loaded? 
    // instantiate my library! 
}); 

아이디어가 있으십니까?

답변

0

나는 그런 일이 게으른로드 믿고,하지만 당신은 rootScope 사용 미친 해킹을 할 수있는 :

angular.module('test').directive('load-menu', function ($rootScope) { 
    console.log('i am the menu for the draw2d library'); 
    // assuming this directive loads the menu 
    $rootScope.menuDirectiveLoaded = true; 
}); 

angular.module('test').directive('the-canvas', function ($rootScope) { 
    console.log('i am the canvas for the draw2d library'); 
    // assuming this directive loads the canvas 
    $rootScope.canvasDirectiveLoaded = true; 
}); 

angular.module('test').controller('areTheDirectivesLoaded', function($rootScope) { 

    // create two watchers for your directive values and if both become true, instantiate the library 
    var keepGoing = true; 
    $rootScope.$watch('canvasDirectiveLoaded', function(newVal, oldVal){ 
     if(newVal === true && $rootScope.menuDirectiveLoaded === true && keepGoing){ 
      ; // instantiate library 
      keepGoing = false; // so as not to instantiate twice 
     } 
    }); 

    $rootScope.$watch('menuDirectiveLoaded', function(newVal, oldVal){ 
     if(newVal === true && $rootScope.canvasDirectiveLoaded === true && keepGoing){ 
      ; // instantiate library 
      keepGoing = false; // so as not to instantiate twice 
     } 
    }); 



}); 
관련 문제