Skip to content

Instantly share code, notes, and snippets.

@janeklb
Last active December 17, 2015 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janeklb/5544464 to your computer and use it in GitHub Desktop.
Save janeklb/5544464 to your computer and use it in GitHub Desktop.
AngularJS '&' directive scope - 1
<div ng-app="myApp" ng-controller="myController">
<div my-clicky my-click-action="doStuff()"></div>
</div>
var app = angular.module('myApp', []);
app.controller('myController', function($scope) {
// some feature that we'll want to surface to our directive:
$scope.doStuff = function() {
console.log(Math.ceil(Math.random() * 100));
};
});
app.directive('myClicky', function() {
return {
scope: {
// here we set up the binding
// linking to the value
// of the 'my-click-action' attribute
myClickAction: '&'
},
// and we connect the expression
// to the directive's template via 'ng-click'
template: '<a ng-click="myClickAction()">Click Action</a>'
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment