Last active
December 28, 2015 03:38
-
-
Save tastywheat/7436032 to your computer and use it in GitHub Desktop.
extending an angular directive
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
.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