ahhmarr
ahhmarr

Reputation: 2295

reuse directive multiple times in angular

I'm trying to create a reusable directive which will do some operation on click

my directive code is

app.directive('share',['$cordovaSocialSharing',function($cordovaSocialSharing)
{ 
    return {
        restrict : 'A',
        scope : {

        },
        link : function(scope,elm,attr)
        {
            elm.bind('click',function()
            {
                console.log('called share service');
                });
        }
    };
   }]);

only the first instance of the directive is getting executed on click the remaining instances are getting ignored

Upvotes: 0

Views: 226

Answers (1)

Martin Da Rosa
Martin Da Rosa

Reputation: 452

Is correct the html? Is a attribute directive ( the restrict param is 'A'):

<button share>
  Click me!
</button>

<button share>
 Or click me!
</button>

http://jsfiddle.net/HB7LU/18220/

That should work!

Upvotes: 1

Related Questions