0

is it possible to write the following code using the ng-if directive insteade of ng-show?

<tbody data-ng-repeat="storedata in storedata.data">
        <tr class="table_row_{{childItem}}">            
            <td class="table_col1" >
                <div ng-show="!storedata.hideButtons" class="btn-group  pull-right">
                    <button type="button" class="btn btn-default" aria-label="Edit" ng-click="openStore(storedata.storeId, storedata)"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></button>
                    <button type="button" class="btn btn-default" aria-label="New" ng-click="openStore(storedata.storeId)"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>
                </div>
            </td>
2
  • 5
    Yes... Have you tried it? Commented Jan 25, 2016 at 18:54
  • Should really be asking questions when there is a legitimate problem. This question doesn't imply any problems. If something isn't working then explain that part Commented Jan 25, 2016 at 19:00

1 Answer 1

1

Should be fine, unless some other javascript code is explicitly relying on the buttons to be present to pass some custom validation.

ng-show merely hides the element using CSS.

ng-if completely removes the element from DOM.

ng-if is slower because modifying DOM requires more processing power. But it is useful when you have ie. form elements which you do not want to have their value appear in the result. Because a hidden element using ng-show will still be validated (and will cause a form to fail validation even if it's hidden), where if you use ng-if it won't be validated.

Sign up to request clarification or add additional context in comments.

1 Comment

since ng-show is working good , I will stick to it , my app is already slow so no need to be slower , thanks

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.