diff options
| author | Jeremy Wilken | 2013-05-17 09:55:22 -0500 |
|---|---|---|
| committer | Pete Bacon Darwin | 2013-05-17 19:16:55 +0100 |
| commit | a7ba27b92c4363a88a4f8706a72d6c3e4ff8ce01 (patch) | |
| tree | cfbd2ac216b21ea1d04bf573e4ec54d740b49616 /docs/content/guide | |
| parent | 2a7043fa2327ecb681f306612a96dbf29ec499e7 (diff) | |
| download | angular.js-a7ba27b92c4363a88a4f8706a72d6c3e4ff8ce01.tar.bz2 | |
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.
Diffstat (limited to 'docs/content/guide')
| -rw-r--r-- | docs/content/guide/dev_guide.services.$location.ngdoc | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/docs/content/guide/dev_guide.services.$location.ngdoc b/docs/content/guide/dev_guide.services.$location.ngdoc index 788fe9a7..027a2332 100644 --- a/docs/content/guide/dev_guide.services.$location.ngdoc +++ b/docs/content/guide/dev_guide.services.$location.ngdoc @@ -619,21 +619,25 @@ to the $location object (using {@link api/ng.directive:input.text ngModel} directive on an input field), you will need to specify an extra model property (e.g. `locationPath`) with two watchers which push $location updates in both directions. For example: -<pre> -<!-- html --> -<input type="text" ng-model="locationPath" /> -</pre> -<pre> -// js - controller -$scope.$watch('locationPath', function(path) { - $location.path(path); -}); - -$scope.$watch('$location.path()', function(path) { - scope.locationPath = path; -}); -</pre> - +<example> +<file name="index.html"> +<div ng-controller="LocationController"> + <input type="text" ng-model="locationPath" /> +</div> +</file> +<file name="script.js"> +function LocationController($scope, $location) { + $scope.$watch('locationPath', function(path) { + $location.path(path); + }); + $scope.$watch(function() { + return $location.path(); + }, function(path) { + $scope.locationPath = path; + }); +} +</file> +</example> # Related API |
