簡體   English   中英

如何從角度js中的自定義服務click事件中調用自定義指令中的方法?

[英]how to call a method in custom Directive from custom services click event in angular js?

我的具有綁定到click事件的自定義服務主體的項目,當在服務中單擊主體時,需要在自定義指令中調用resetDropdown()函數。 我該怎么辦,請幫我兄弟?

I tried code bellow that is first one is custom directive contain method.

.directive('dropdownMenu',['$ parse','$ compile','DropdownService','$ templateCache',function($ parse,$ compile,DropdownService,$ templateCache){return {限制:'A',替換:false,ngTransclude:true,范圍:{dropdownMenu:'=',dropdownModel:'=',dropdownItemLabel:'@',dropdownOnchange:'&',dropdownDisabled:'=',dropdownSubmit:'&'},

  $scope.resetDropdown = function(){
              alert("calling reset Dropdown by me");
          }
}

}); 具有代碼.factory('DropdownService',['$ document',function($ document,$ rootScope,$ scope)的下一個自定義服務,{var body = $ document.find('body'),

      body.bind('click', function (event, $scope, $rootScope) {
            resetDropdown();
    });
    when body clicked resetDropdown method need to call how can i do please help me. 

我不知道到底需要什么。 但是您的指令方法在$ scope中,並且您試圖在$ rootScope中調用方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM