Search code examples
javascriptangularjsangular-ng-if

AngularJS does my model data become invalid if ng-if evaluates to false?


Let's say that I have something like

<div ng-if="{{someCondition}}">
    <input type="text" ng-model="myVariable"/>
</div>

If someCondition is false and that DIV gets removed from the DOM, what, if anything happens to $scope.myVariable?


Solution

  • Nothing happens (see reference).

    ng-if just determines if the html element is created in the DOM. When it exist the <input> value is bidirectionally binded to $scope.myVariable.