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

3
  • I think ng-attr-st_sort="col.sortField" should work? Commented Jan 6, 2015 at 7:15
  • what happened when col.sortField is undefined? rendered what? the directive has any template? Commented Jan 6, 2015 at 7: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) Commented Jan 6, 2015 at 18:46

1 Answer 1

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

            })
        }
    };
}])
Sign up to request clarification or add additional context in comments.

3 Comments

Thank's for your answer but the directive st-sort is not mine (but part of the Smart Table plugin).
Copy the stSort directive from smart table code, and rewrite it. It is not bad idea.
yes this is a true idea. THe bad thing is evolutivity but I will consider this solution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.