Actually all I need is somewhere to put a reusable function that has access to $scope.
Here's an attempt at a simplified example of what I'm trying to do: Plnkr
I'm still getting the hang of directives.
var app = angular.module('plunker', []);
app.directive('dir1', function() {
return {
restrict: 'AE',
link: function(scope, element, attrs) {
element.click(function() {
scope.message = "Hey Now";
scope.doSomething();
});
}
};
});
app.directive('dir2', function() {
return {
restrict: 'AE',
link: function(scope, elem, attr) {
scope.doSomething = function() {
alert($scope.message);
}
}
};
});
and:
<html ng-app="plunker" >
<head>
<meta charset="utf-8">
<title>AngularJS Plunker</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js"></script>
<script src="app.js"></script>
</head>
<body>
<dir1>click me</dir1>
</body>
</html>