Skip to content

Commit

Permalink
docs(ngModelController): $parent can help isolate scope directives
Browse files Browse the repository at this point in the history
  • Loading branch information
basarat authored and jamesdaily committed Jan 27, 2014
1 parent f14add4 commit 3cd55e6
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/ng/directive/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -939,14 +939,14 @@ var VALID_CLASS = 'ng-valid',
* Note that if you have a directive with an isolated scope, you cannot require `ngModel`
* since the model value will be looked up on the isolated scope rather than the outer scope.
* When the directive updates the model value, calling `ngModel.$setViewValue()` the property
* on the outer scope will not be updated.
* on the outer scope will not be updated. However you can get around this by using $parent.
*
* Here is an example of this situation. You'll notice that even though both 'input' and 'div'
* seem to be attached to the same model, they are not kept in synch.
* Here is an example of this situation. You'll notice that the first div is not updating the input.
* However the second div can update the input properly.
*
* <example module="badIsolatedDirective">
<file name="script.js">
angular.module('badIsolatedDirective', []).directive('bad', function() {
angular.module('badIsolatedDirective', []).directive('isolate', function() {
return {
require: 'ngModel',
scope: { },
Expand All @@ -961,8 +961,9 @@ var VALID_CLASS = 'ng-valid',
});
</file>
<file name="index.html">
<input ng-model="someModel">
<div bad ng-model="someModel"></div>
<input ng-model="someModel"/>
<div isolate ng-model="someModel"></div>
<div isolate ng-model="$parent.someModel"></div>
</file>
* </example>
*
Expand Down

0 comments on commit 3cd55e6

Please sign in to comment.