我有$scope.number = 1
.我想添加一个侦听器来更新路径。
我的尝试不起作用:
function LocationController($scope, $location) {
$scope.$watch($scope.number, function(path) {
$location.path('/'+$scope.number);
});
}
另外,$scope.number
如何称呼对象,子对象?
试试
function LocationController($scope, $location) {
$scope.$watch('number', function(newNumber) {
$location.path('/'+newNumber);
});
}
阅读文档以了解要$watch
的参数