I\'m trying to understand the difference between ng-if
and ng-show
/ng-hide
, but they look the same to me.
Is there a differenc
One important thing to note about ng-if and ng-show is that when using form controls it is better to use ng-if
because it completely removes the element from the dom.
This difference is important because if you create an input field with required="true"
and then set ng-show="false"
to hide it, Chrome will throw the following error when the user tries to submit the form:
An invalid form control with name='' is not focusable.
The reason being the input field is present and it is required
but since it is hidden Chrome cannot focus on it. This can literally break your code as this error halts script execution. So be careful!