I'm trying to make an in-place editor directive. I've seen few directive examples and all of them using hidden input elements to switch edit/view mode. I don't want to clutter my DOM with lots of hidden elements (considering if I have lots of table rows I want to edit in place). So I was thinking if I can have a directive which renders input elements when I double click on something I want to edit and when I cancel edit mode, it should be removed.
What I'm assuming I should do is: In my directive linker I should have a method that renders my input elements for in-place editing and I should be calling this method in my click handler.
<span ng-click="editInPlace()">Edit me</span>
controller:
...
$scope.editInPlace = function(){
this.renderEditor();
}
Directive
...
link: function (scope, elem, attrs) {
scope.renderEditor= function () {
//code to show inputs
}
}
Is this direction correct? Or there are better approaches?
Thanks!
Amit