Good morning, i have a field, when it is viewed it is a label, when it is modified it is an input field, i trigger this with ng-show and ng-hide and a button that enables a boolean value. When i activate the editing mode the label hides and the input field shows, it is in realtime, when i click cancel and switch the boolean, the label appears but the input field takes some time to hide, so i have a very bad visual effect. here some code
<input ng-model="name" ng-show="editing">
<label ng-hide="editing">{{name}}</label>
<button ng-click="editing=true">Edit</button>
<button ng-click="editing=false">Cancel</button>
is there a way to fix this issue?
Thank you
ngShow and ngHide are two ng directives in AngularJS used to show and hide the elements respectively.
Absolutely not. First of all, the two directives can trip over each other( see this JSFiddle, as provided by Joel Skrepnek), and is generally just bad design.
ng-if is better in this regard. Using it in place of ng-show will prevent the heavy content from being rendered in the first place if the expression is false. However, its strength is also its weakness, because if the user hides the chart and then shows it again, the content is rendered from scratch each time.
ng-if can only render data whenever the condition is true. It doesn't have any rendered data until the condition is true. ng-show can show and hide the rendered data, that is, it always kept the rendered data and show or hide on the basis of that directives.
do you have ngAnimate included?
if so, this can happen. At our projects we declare and use a class on every dom element where we want to animate, and we tell angular to animate just those elements in the config callback:
$animateProvider.classNameFilter(/animate/);
I had the same problem all the time I had to elements with the same var to hide/show (because ng-animate) , this happens with ng-show / ng-hide / ng-if and maybe also with ng-switch but not with ng-class. So a quick fix is change your code for:
<input ng-model="name" ng-class="{'ng-hide':!editing}">
<label ng-class="{'ng-hide':editing}">{{name}}</label>
<button ng-click="editing=true">Edit</button>
<button ng-click="editing=false">Cancel</button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With