create a single html view for multiple partial views in angularjs

后端 未结 3 1401
自闭症患者
自闭症患者 2020-12-01 01:59

I wish to create a single html file with multiple tags. These should act as separate individual views that are usually kept in partials folder. And then i wish to specify

3条回答
  •  醉话见心
    2020-12-01 02:50

    You could use ng-switch to conditionally render your productList with an include, depending on the route parameters.

    Try this in your config:

        angular.module('productapp', [])
          .config(['$routeProvider', function($routeProvider) {
          $routeProvider
            .when('/productapp', {templateUrl: 'partials/productList.html', controller: productsCtrl})
            .when('/productapp/:productId', {templateUrl: 'partials/productList.html', controller: productsCtrl})
            .otherwise({redirectTo: '/productapp'});
    

    And in your controller:

        function productsCtrl($scope, $routeParams) {
          $scope.productId = $routeParams.productId;
        }
    

    And in your html:

        <...productListHtml...>
        

提交回复
热议问题