当角航线()不映射到控制器或模板 [英] Angular route when() without mapping to controller or template
本文介绍了当角航线()不映射到控制器或模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是可能的()时没有映射使用任何控制器或模板?
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-视图
是必要的。
这篇关于当角航线()不映射到控制器或模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文