You've got it right, you just need to reference myDirective as my-directive when it's in the DOM.
On Monday, September 14, 2015 at 9:40:03 AM UTC-6, Cool Zebra wrote: > > I am new to Angular and am trying to create a directive that listens for > event handlers. I have a plunker > > http://plnkr.co/edit/3EpSipEm2B16qNfHfNIx?p=preview > > Here is my script.js > > var app = angular.module('myApp', []); > > > app.controller('myCtrl', function ($scope) { > $scope.numbers = [1,4,7,10,13,72,56,54,89,132,159,19]; > }); > > > app.directive('myDirective', function() { > return { > restrict: 'A', > link: function(scope, element, attrs) { > element.bind('click', function() { > alert('hi'); > }); > } > }; > }); > > Here is my index.html > > <!doctype html> > <html ng-app="myApp"> > <head> > <script src=" > http://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js" > ></script> > <script src="script.js"></script> > > > </head> > <body ng-controller="myCtrl"> > <p>{{numbers}}</p> > <button myDirective>Click Here</button> > > > </body> > </html> > > I'm not sure why this doesn't work. Any help will be appreciated. > -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
