Reputation: 4177
does ng-form directive creates a new sub scope in angular js ?
Had been googling for half hour couldnt find much.
Upvotes: 2
Views: 704
Reputation: 544
Nope. You can tell from this plunker that ng-form
does not create a new scope.
<h2>Parent Scope</h2>
<input ng-model="name" />
<p>Hello {{name}}!</p>
<h2>ng-form</h2>
<ng-form>
<input ng-model="name" />
<p>Hello {{name}}!</p>
</ng-form>
<h2>ng-if</h2>
<div ng-if="true">
<input ng-model="name" />
<p>Hello {{name}}!</p>
</div>
The way you can tell is the same reason you should never put a primitive on the scope. If you change the first two inputs, the name
variable changes for all three. But if you change the last input, it will only change there. And after that point it will stop responding to changes made on the first two input boxes (since previously it was using the parent scope's name
variable, but once you interact with it from within that scope, it has its own variable).
Upvotes: 2