0

I have a template used in a directive, looking like :

<tr>
    <th ng-repeat="col in tableSpec" st-sort="{{col.sortField}}"></th>
</tr>

The attribute st-sort should not be render (no attribute at all) when the col.sortField doesn't exists.

I've read about the 'allOrNothing' option in the $interpolate witch does what I want but I don't if it is possible to specify this option when using the {{ }} notation.

I've read also about the ngAttr and I try to use this notation ng-attr-st_sort="{{col.sortField}}" but without success anymore.

Any healp would be greatly appreciated.

Jean-Marc

jmcollin92
  • 2,896
  • 6
  • 27
  • 49
  • I think ng-attr-st_sort="col.sortField" should work? – xi.lin Jan 06 '15 at 07:15
  • what happened when col.sortField is undefined? rendered what? the directive has any template? – Mehmet Otkun Jan 06 '15 at 07:33
  • Thank's for your answers. I try with st-sort="{{undefined}}" and I got st-sort in return. I try also with ng-attr-st_sort and the result is the same : in result I've got the empty attribute st-sort. The directive st-sort is not mine (it is provided by the Smart Table plugin) – jmcollin92 Jan 06 '15 at 18:46

1 Answers1

0

As I understand, your directive stSort has a template. You can add ngHide directive to you template root element, and $observer condition if col.sortField exists or not?

.directive('stSort', [function () {
    return {
        restrict: 'EA',
        template: '<div ng-hide="$notRender"></div>',
        link: function(scope, element, attrs) {
            attrs.$observe('stSort', function(newVal, OldVal){
                 if(!newVal)
                     scope.$notRender = true
                 else
                    scope.$notRender = false;

                 //do your staff

            })
        }
    };
}])
Mehmet Otkun
  • 1,374
  • 9
  • 22