A Hassan
A Hassan

Reputation: 119

AngularJS ng-if and DOM Compilation

I am using a datepicker control on my page which is rendered through ng-if dependent on a specific dropdown value.

The problem I'm facing is since at the time of rendering, that datepicker input is not part of DOM, so later when I change the value of dropdown, the datepicker control does not work.

If I use ng-show, I encounter issues in validations.

Any suggestions?

Thanks.

Upvotes: 2

Views: 196

Answers (2)

Aji Aneesh
Aji Aneesh

Reputation: 131

Try "$scope.apply()" after the toggling of ng-if variable.

Upvotes: 0

Ramesh Rajendran
Ramesh Rajendran

Reputation: 38683

Use ng-show/ng-hide instead of ng-if, because the ng-if directive removes or recreates a portion of the DOM tree based on an expression. If the expression assigned to ng-if evaluates to a false value then the element is removed from the DOM, otherwise a clone of the element is reinserted into the DOM.

More details. please refer this link : what is the difference between ng-if and ng-show/ng-hide

Upvotes: 1

Related Questions