Last active
December 17, 2015 03:49
-
-
Save janeklb/5546011 to your computer and use it in GitHub Desktop.
AngularJS '&' directive scope - 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div ng-app="myApp" ng-controller="myController"> | |
<div my-clicky my-click-action="doStuff(number)"></div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = angular.module('myApp', []); | |
app.controller('myController', function($scope) { | |
// some feature that we'll want to surface to our directive: | |
// this time with an argument | |
$scope.doStuff = function(number) { | |
if (typeof number == 'undefined') number = 100; | |
console.log(Math.ceil(Math.random() * number)); | |
}; | |
}); | |
app.directive('myClicky', function() { | |
return { | |
scope: { myClickAction: '&' }, | |
// this time we pass an "argument hash" to the click action | |
template: '<a ng-click="myClickAction({number:1000})">Click Action</a>' | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment