UPDATED
Using transclusion in your directive provides you with options for manipulating the DOM with access to the transcluded content in the compile/link function. There, you may use jqLite to overwrite the contents of the parent with the contents of the clone
:
JavaScript:
angular.module('myApp', [])
.controller('MyController', function($scope){
$scope.condition = true;
// $scope.othercondition = true;
$scope.items = [1, 2, 3, 4];
$scope.obj = {
name: ''
};
})
.directive('myDirective', function(){
return {
transclude: true,
replace: true,
template: '<div ng-transclude></div>',
compile: function(tElem, tAttrs, transclude) {
return {
pre: function(scope, element) {
transclude(scope, function(clone){
element.parent().empty().append(clone);
});
}
}
}
}
});
index.html:
<td>
<div ng-if="condition" my-directive ><input type="text" ng-model="obj.name" /></div>
<ul ng-if="othercondition">
<li ng-repeat="item in items">{{item}}</li>
</ul>
</td>