Search code examples
angularjsangularjs-directiveangular-ng-if

Add nf-if condition for custom directive property


Below is the example of my custom directives

<div ng-if="activitedTab == 'individual-accounts'">
    <ind-table tmodel="choosenInfo.section1.src" ttype="{{activitedTab}}" clickaction="popup"></ind-table>
</div>

How can i put a condition for the property clickaction so that this property could be included only if the value of scope variable contentLength is true. I tried below way.

<div ng-if="activitedTab == 'individual-accounts'">
    <ind-table tmodel="choosenInfo.section1.src" ttype="{{activitedTab}}" ng-if="contentLength" clickaction="popup"></ind-table>
</div>

But if the value of contentLength become false then entire section is not displayed. I just want to exclude clickaction property if the value of contentLength is false.


Solution

  • Remove the ng-if condition from the custom directive and use the ternary operator as-

    clickaction="contentLength > 0 ? popup : '' "