0

I have the following code :

<div ng-controller="myCtrl">
     <div ng-if="myVar">
        <input ng-model="query">
     </div>
</div>

where myVar is true

  • When the <input> is within the ng-if the query variable isn't created in the $scope.
  • When it's outside the div (but still within the ng-controller) it works well.

Any idea why ?!

Matthieu Riegler
  • 31,918
  • 20
  • 95
  • 134

1 Answers1

1

Because ngIf creates new scope. Either use a dot in the model, or the ControllerAs syntax.

Community
  • 1
  • 1
przno
  • 3,476
  • 4
  • 31
  • 45