mail ramesh
mail ramesh

Reputation: 9

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. 

Upvotes: 0

Views: 112

Answers (1)

shrish
shrish

Reputation: 13

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

Upvotes: 0

Related Questions