[英]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.