所有类别只有一个模板的angularJs?

所有类别只有一个模板的angularJs?,angularjs,angular-routing,Angularjs,Angular Routing,对不起,我的英语不好! 我已仿效这个例子 这是一个类别(电话列表和详细信息空间模板)。 例如,我通过url(localhost/myApp/#/car..localhost/myApp/#/phone..)在一个category.html文件(car、phone、fashion)中有许多category 主布局 <div ng-view></div> 部分模板html(category.html) 当我调用path/#/fashion时,它同时显示两种样式,但我只需

对不起,我的英语不好! 我已仿效这个例子 这是一个类别(电话列表和详细信息空间模板)。 例如,我通过url(localhost/myApp/#/car..localhost/myApp/#/phone..)在一个category.html文件(car、phone、fashion)中有许多category

主布局

<div ng-view></div>
部分模板html(category.html)

当我调用path/#/fashion时,它同时显示两种样式,但我只需要一种样式或一辆车 _那么解决方案在哪里呢?
谢谢你的帮助

听起来您想要的是共享控制器和模板(常见场景)

因此,您不需要配置多条路由,只需要一条路由:

.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);
}])

示例:

我建议不要将不同类别的模板组合到一个HTML文件中。如果您有特定的理由认为必须这样做,请告诉我们,以便我们可以尝试并建议更好的解决方案(不涉及一个大模板)。感谢您的回复,因此每次我向数据库添加新类别时,我都必须添加一个新模板/部分。何时交付给最终用户和数据更改?最终用户代码或i代码,然后转发
.config(['$routeProvider',
function($routeProvider) {
  $routeProvider
    // route for fashion
    .when('/:category', {
      templateUrl: 'partials/category.html',
      controller: 'categoryController'
     })
.controller('categoryController', ['$scope', '$routeProvider', function($scope, $routeParams) {
    $scope.category = $routeParams.category;
    $scope.items = fetchFromService($routeParams.category);
}])