Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a7ba27b

Browse files
gnomeontherunpetebacondarwin
authored andcommitted
doc(guide:$location): fix example for two way databinding.
When you are watching the $location.path(), it has to be wrapped in a function since it is not attached to the scope and if you pass a string to $scope.$watch it is evaluated against the $scope.
1 parent 2a7043f commit a7ba27b

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

docs/content/guide/dev_guide.services.$location.ngdoc

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -619,21 +619,25 @@ to the $location object (using {@link api/ng.directive:input.text
619619
ngModel} directive on an input field), you will need to specify an extra model property
620620
(e.g. `locationPath`) with two watchers which push $location updates in both directions. For
621621
example:
622-
<pre>
623-
<!-- html -->
624-
<input type="text" ng-model="locationPath" />
625-
</pre>
626-
<pre>
627-
// js - controller
628-
$scope.$watch('locationPath', function(path) {
629-
$location.path(path);
630-
});
631-
632-
$scope.$watch('$location.path()', function(path) {
633-
scope.locationPath = path;
634-
});
635-
</pre>
636-
622+
<example>
623+
<file name="index.html">
624+
<div ng-controller="LocationController">
625+
<input type="text" ng-model="locationPath" />
626+
</div>
627+
</file>
628+
<file name="script.js">
629+
function LocationController($scope, $location) {
630+
$scope.$watch('locationPath', function(path) {
631+
$location.path(path);
632+
});
633+
$scope.$watch(function() {
634+
return $location.path();
635+
}, function(path) {
636+
$scope.locationPath = path;
637+
});
638+
}
639+
</file>
640+
</example>
637641

638642
# Related API
639643

0 commit comments

Comments
 (0)