Hi,
I made a directive 'draggable' to drag a div -element (duh...). What is
does is:
1) prepend a title-bar to the element with a (x) allowing to close te
element-window
2) make the element draggable.
This works fine. I have a q about refactoring:
Currently insertion of the title-bar is performed by the link function. No
big deal since there is only 1 element to manipulate by the directive. But
the Angular way says DOM manipulation should be done by the compile
function, not by link. So my q is: how can I transform my current
directive, containing just a link function, to a directive that has a
compile function and a link function? The compile function should prepend a
template to the element, the link function should just make the element
draggable. I have this code (abbreviated for clarity)
.directive('draggable',function(){
return{
restrict: 'A',
transclude: true,
replace: false,
template: '<div><div style="width:100%; height:20px;
background-color:#ccc; border-radius:10px;"><span class="glyphicon
glyphicon-remove-circle" style="float:right;font-size:1.5em;"
ng-click="show=false"></span></div><div ng-transclude></div></div>',
link: function(scope,element,attrs){
$(element.context).on('mousedown',handleMousedown);
[...]
}
This setup works - it prepends a titlebar to the element and the element is
draggable. Just want to know how to refactor.
Thanks,
Marc
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.