I have the following element,
<button test-directive>value</button>
I know I can use the ng-click directive
, but then I have to call a function from the controller. When the user clicks, I want to fire a directive called in example test-directive
testModule.directive('testDirective', function(){
return {
restrict: 'A',
link: function(scope, element, attrs) { }
}
})
how can I implement the ng-click in this directive?
Thank You
Not sure if I got your idea.
Here is the plunker
directive('testDirective', function(){
return {
restrict: 'A',
replace:true,
template:'<button ng-click="fire()">test</button>',
controller:function($scope, $element, $attrs){
$scope.fire = function (){
console.log("fire !");
};
}
};
});
maxisam answer is correct but
you can use
<span test-directive>value</span>
instead of <button test-directive>value</button>
it will still display button.