Skip to content

Commit 772fb61

Browse files
basaratjamesdaily
authored andcommitted
docs(ngModelController): $parent can help isolate scope directives
1 parent 45cadd7 commit 772fb61

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/ng/directive/input.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -939,14 +939,14 @@ var VALID_CLASS = 'ng-valid',
939939
* Note that if you have a directive with an isolated scope, you cannot require `ngModel`
940940
* since the model value will be looked up on the isolated scope rather than the outer scope.
941941
* When the directive updates the model value, calling `ngModel.$setViewValue()` the property
942-
* on the outer scope will not be updated.
942+
* on the outer scope will not be updated. However you can get around this by using $parent.
943943
*
944-
* Here is an example of this situation. You'll notice that even though both 'input' and 'div'
945-
* seem to be attached to the same model, they are not kept in synch.
944+
* Here is an example of this situation. You'll notice that the first div is not updating the input.
945+
* However the second div can update the input properly.
946946
*
947947
* <example module="badIsolatedDirective">
948948
<file name="script.js">
949-
angular.module('badIsolatedDirective', []).directive('bad', function() {
949+
angular.module('badIsolatedDirective', []).directive('isolate', function() {
950950
return {
951951
require: 'ngModel',
952952
scope: { },
@@ -961,8 +961,9 @@ var VALID_CLASS = 'ng-valid',
961961
});
962962
</file>
963963
<file name="index.html">
964-
<input ng-model="someModel">
965-
<div bad ng-model="someModel"></div>
964+
<input ng-model="someModel"/>
965+
<div isolate ng-model="someModel"></div>
966+
<div isolate ng-model="$parent.someModel"></div>
966967
</file>
967968
* </example>
968969
*

0 commit comments

Comments
 (0)