Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to call the directive on button click inside custom directive

Hi i am working on custom directives of angularjs. I just want to know that how to call the directive when I click the button. Please suggested me how to achieve this.

Thanks

like image 613
user3836920 Avatar asked Jul 18 '14 04:07

user3836920


People also ask

How do I invoke a directive in AngularJS?

In addition to all the built-in AngularJS directives, you can create your own directives. New directives are created by using the . directive function. To invoke the new directive, make an HTML element with the same tag name as the new directive.

What is custom directive in angular8?

What is an Angular Directive? Directives are the functions which will execute whenever Angular compiler finds it. Angular Directives enhance the capability of HTML elements by attaching custom behaviors to the DOM.


1 Answers

The following example shows a sample custom directive which can handle click events; This is a scope-independent directive. And the appRoot module has to be defined earlier.

<div ng-controller="MyController">
    <button custom-click="">Click Me</button>
</div>

appRoot.directive('customClick', function() {
    return {
        link: function(scope, element, attrs) {
          element.click(function(){
           //Do something useful
          }); 
        }
    }
});
like image 71
Vidhya Sagar Reddy Avatar answered Oct 05 '22 10:10

Vidhya Sagar Reddy