mainLayout
<div ng-view></div>
js file
.config(['$routeProvider',
function($routeProvider) {
$routeProvider
// route for fashion
.when('/fashion', {
templateUrl: 'partials/category.html',
controller: 'fashionCtrl'
})
// route for car
.when('/car', {
templateUrl: 'partials/category.html',
controller: 'carCtrl'
})
.. controller for fashionCtrl and carCtrl
部分模板html(category.html)
template for car
...................
template for fashion
...................
template for phone
template for car
...................
template for fashion
...................
template for phone
当我调用路径/#/ fashion时它会显示两者,但我只想要一种时尚或汽车
_那么解决方案在哪里?
谢谢你的帮助!
答案 0 :(得分:0)
听起来你正在寻找的是共享控制器和模板(常见场景)......
因此,您只需要一条路线,而不是配置多条路线:
.config(['$routeProvider',
function($routeProvider) {
$routeProvider
// route for fashion
.when('/:category', {
templateUrl: 'partials/category.html',
controller: 'categoryController'
})
在您的控制器中,然后使用$ routeParams获取当前选定的类别,并使用该公共数据填充模板。
.controller('categoryController', ['$scope', '$routeProvider', function($scope, $routeParams) {
$scope.category = $routeParams.category;
$scope.items = fetchFromService($routeParams.category);
}])