Javascript ngroute支持多个url参数
我在操作ng路由功能方面有很大的差距。 以下是我想要实现的:我有一个指向dashboard.html的主页和另一个 buildings.html。 可以使用许多参数调用buildings页面,例如:id、类型、颜色 所以传统的url应该是这样的:Javascript ngroute支持多个url参数,javascript,angularjs,Javascript,Angularjs,我在操作ng路由功能方面有很大的差距。 以下是我想要实现的:我有一个指向dashboard.html的主页和另一个 buildings.html。 可以使用许多参数调用buildings页面,例如:id、类型、颜色 所以传统的url应该是这样的: /buildings?id=110&type=special&color=red 据我所知,我应该有这样的结构: $routeProvider // route for the main page which
/buildings?id=110&type=special&color=red
据我所知,我应该有这样的结构:
$routeProvider
// route for the main page which will direct to the buildings page
.when('/', {
templateUrl : 'web/pages/dashboard.html',
controller : 'dashboardController',
controllerAs : 'dashboard'
})
// route for the main page which will direct to the buildings page
.when('/buildings/:buildingId/:buildingType/:buildingColor', {
templateUrl : 'web/pages/buildings.html',
controller : 'mainController',
controllerAs : 'buildings'
})
;
});
url应该如下所示:
/buildings/110/special/red
我不明白的是,如何调用只有id或带有类型和颜色的buildings页面?
如果我有7个参数,并且只想用3个参数触发一个调用,我应该怎么做
我使用$location.path在需要时根据gui事件在页面之间切换,例如:
$location.path('/buildings/'+$scope.id)
谢谢。您有三个选择:
- 或者,您需要设置参数,这样当您想要使用param 5时,您可以确定,之前的param也必须定义
- 或者您可以只使用一些表示null的字符,比如-,或者其他什么。您的URL看起来像
/buildings/5/-/red
- 或者(最好的选择)您应该在URL中保留必需的参数(如ID),并在URL get参数中放置可选参数(如您在oldschool样式参数中所示)。然后您的URL将如下所示:
。您可以使用/buildings/5?color=red
等从AngularJS访问这些参数$location.search().color
$location.url('/buildings/5?color=red&type=special')代码>b)$location.search('color','red')。search('type','special')。path('/buildings/5')代码>是的,但是如果我使用第三种方法,我如何使用angular生成传统的url?也有人说不建议这样做,因为这样会使页面重新加载。你说的传统URL字符串是什么意思?使用带有相对URL的$location服务不会使页面以角度重新加载。