这是可能的()时没有映射使用任何控制器或模板?
It's possible to use when() without mapping to any controller or template?
这是我如何配置我的路线:
This is how I have configured my routes:
app.config(function($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider
.when('/presentations/:id', {});
});
我需要在我的控制器使用routeParams:
I need to use routeParams in my controller:
app.controller('PresentationController', function($scope, $routeParams) {
console.log($routeParams);
});
这是行不通的。我不需要ngView但我添加它需要的情况下。我的控制器已经加载了NG-控制器指令。
This doesn't work. I don't need ngView but I added it in case is needed. My controller is already loaded with the ng-controller directive.
一个人连续观看 $ routeParams.id
在这种情况下的变化:的 http://plnkr.co/edit/x2cPxVWPqVePDule1aOk?p=$p$pview
One has to continuously watch the $routeParams.id
for changes in this case: http://plnkr.co/edit/x2cPxVWPqVePDule1aOk?p=preview
$scope.$watch(function () { return $routeParams.id; }, function (newVal) {
if (typeof newVal === 'undefined') return;
$scope.id = newVal;
})
此外,其在模板的 NG-视图
是必要的。