Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have a directive template keep element content?

I'm trying to add ng-click to a button. My HTML:

<button class="btn">clicky</button>

And the directive:

angular.module('app').directive('btn', function() {
  return {
    restrict: 'C',
    replace: true,
    scope: true,
    transclude: true,
    template: '<button ng-click="onClick()"></button>'
  };
});

It removes clicky from the element.

Transclude doesn't help. Thanks for any answers.

like image 484
Mosho Avatar asked Mar 21 '14 06:03

Mosho


1 Answers

Add ng-transclude in template.

template: '<button ng-click="onClick()" ng-transclude></button>'
like image 96
Nitish Kumar Avatar answered Oct 29 '22 17:10

Nitish Kumar