Skip to content

Commit 5963b5c

Browse files
committed
docs(guide/$location): update note about getter/setters
1 parent 621f678 commit 5963b5c

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

docs/content/guide/$location.ngdoc

+8-14
Original file line numberDiff line numberDiff line change
@@ -618,27 +618,21 @@ then uses the information it obtains to compose hashbang URLs (such as
618618

619619
## Two-way binding to $location
620620

621-
The Angular's compiler currently does not support two-way binding for methods (see [issue](https://github.com/angular/angular.js/issues/404)). If you should require two-way binding
622-
to the $location object (using {@link input[text] ngModel} directive on an input
623-
field), you will need to specify an extra model property (e.g. `locationPath`) with two {@link ng.$rootScope.Scope#$watch $watchers}
624-
which push $location updates in both directions. For example:
621+
Because `$location` uses getters/setters, you can use `ng-model-options="{ getterSetter: true }"`
622+
to bind it to `ngModel`:
623+
625624
<example module="locationExample">
626625
<file name="index.html">
627626
<div ng-controller="LocationController">
628-
<input type="text" ng-model="locationPath" />
627+
<input type="text" ng-model="locationPath" ng-model-options="{ getterSetter: true }" />
629628
</div>
630629
</file>
631630
<file name="script.js">
632631
angular.module('locationExample', [])
633-
.controller('LocationController', ['$scope', '$location', function ($scope, $location) {
634-
$scope.$watch('locationPath', function(path) {
635-
$location.path(path);
636-
});
637-
$scope.$watch(function() {
638-
return $location.path();
639-
}, function(path) {
640-
$scope.locationPath = path;
641-
});
632+
.controller('LocationController', ['$scope', '$location', function($scope, $location) {
633+
$scope.locationPath = function (newLocation) {
634+
return $location.path(newLocation);
635+
};
642636
}]);
643637
</file>
644638
</example>

0 commit comments

Comments
 (0)