简体   繁体   中英

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

MY project having custom services body binded to click event, when clicked on body in service need to call resetDropdown() function in custom directive. how can i do please help me bro?

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 { restrict: 'A', replace: false, ngTransclude:true, scope: { dropdownMenu: '=', dropdownModel: '=', dropdownItemLabel: '@', dropdownOnchange: '&', dropdownDisabled: '=', dropdownSubmit: '&' },

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

}); next custom service having code .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. 

I don't know exactly what is required. But your directive method is in $scope and you are trying to call method in $rootScope.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM