Wednesday 15 January 2014

angularjs - using a directive to invoke a controller function that displays an alert (probably simple) -



angularjs - using a directive to invoke a controller function that displays an alert (probably simple) -

i've been next tutorial , want update code alert displayed when button clicked.

here's fiddle

how beind element mouse click? thought perhaps using like:

.directive('enter', function(){ homecoming function(scope, element, attrs){ element.bind("mouseclick", function(){ scope.$apply("sayhello()"); }) } })

this doesn't work unfortunately. should using ng-click in case? i'm trying follow best practice. based on tutorial i'm next looks best way can sure controller , directive in same scope.

i hope makes sense, i'm new angular.

yup, ng-click want. it, button decalration becomes:

<button ng-click="sayhello()">sayhello</button>

here's updated fiddle, no longer needs come in directive!

angularjs

No comments:

Post a Comment