score:0

Accepted answer

since there is no plunker/fiddle provided, this is an another guess :)

try putting the new element into dom before compling like this:

var newelem = '<div d3-bars bar-height="20" bar-padding="5"></div>';
newelem = angular.element(newelem);
element.append(newelem);
$compile(newelem)(scope);

that is in order to allow the new element to have width and height before get compiled.

score:0

i would guess, that you forgot to assign your scope variable. just try $scope instead if you're in a controller.

another possible apporach would be, to toggle a boolean variable with your button and use ng-show for your d3 code like this:

<button ng-click="showd3 = != showd3">click me!</button>
<div d3-bars bar-height="20" bar-padding="5" ng-show="showd3"></div>

Related Query

More Query from same tag