Skip to content

Instantly share code, notes, and snippets.

@tastywheat
Last active December 28, 2015 03:38
Show Gist options
  • Save tastywheat/7436032 to your computer and use it in GitHub Desktop.
Save tastywheat/7436032 to your computer and use it in GitHub Desktop.
extending an angular directive
.directive('smelly', function(){
return {
restrict: 'E',
controller: function(){
this.doWork = function(){
alert('smelly work');
};
},
link: function($scope, $element, $attributes, controller){
$element.bind('click',function(){
controller.doWork();
});
}
};
})
.directive('xtSmelly', function(){
return {
controller: function($scope){
$scope.name = "brian";
},
scope: {},
require: 'smelly',
link: function($scope, $element, $attributes, controllers){
controllers.doWork = function(){
alert('xt-smelly work: ' + $scope.name);
};
}
};
})
;
//Usage
//<smelly xt-smelly>SMELLY</smelly>
//Result
//alerts "xt-smelly work"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment