我正在使用 $routeParams 服务。
当我在 Controller 中使用 console_log($routeParams)
服务时,我会在控制台中看到所有值。
但是,当我控制台记录 $routeParams.id 时,我得到了未定义。 (当我控制台 $routeParams 时,我看到了参数)
只有使用超时我才能获取值:
$timeout(function() {
$scope.id = $routeParams.id;
}, 100);
知道为什么会发生这种情况吗?这真的很奇怪,我想我错过了一些东西。
最佳答案
我找到了另一种方法:
$scope.$on('$routeChangeSuccess', function() {
// $routeParams.id exists
});
关于javascript - $routeParams 未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34286513/