1

I have $scope.number = 1. I want to add a listener to update the path.

My try which doesn't work:

function LocationController($scope, $location) {
   $scope.$watch($scope.number, function(path) {
     $location.path('/'+$scope.number);
   });
}

Also, how is $scope.number called, object, subobject?

1 Answer 1

1

try

function LocationController($scope, $location) {
   $scope.$watch('number', function(newNumber) {
     $location.path('/'+newNumber);
   });
}

Read the documentation for the arguments to $watch

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.