I seem to have a small issue. I have created a directive and inserted the directive via an attribute on an existing DIV, see below.
<td my-directive>This Text I want to get hold of in my directive</td>
and the directive is displayed here. I did try playing around with element.parent() but this doesn't seem to work.
.directive('myDirective', function () {
return {
template: '<div></div>',
restrict: 'A',
link: function(scope, element, attrs) {
element.text(element.parent().text); // Doesn't work
}
};
});
I want the TD to continue with its normal operation i.e. Displaying the text with the TD element. But its blank, so I thought about re-injecting it in the directive, but why is it blank?
Actually what I am trying to do is any part of the directive is clicked I want to do some internal stuff and then raise an event on the $scope which is shared by controller i.e.
element.click(function(){
//alert("direc clicked");
scope.onClick()
});
Not sure if I am doing this correct.
Anyone done this before ?