0

我正在使用角度,我想知道哪个更好。我有我的模板,我将其拆分为页眉、页脚、侧边菜单和主要内容。我想知道是否每个部分使用一个模块,然后使用另一个模块来封装较小的模块,或者让每个模块具有不同的 ng-app 然后引导。我想知道性能和最佳实践方面的区别。

目前我已经用 UI-router 实现了如下: -

风景

<div  ng-app="baseModule" ng-controller="baseController as base" >
  <div ui-view >

  </div>
</div>

路线:-

 $stateProvider.state('root-profile', {
        abstract: true,
        views: {
            '@': {
                templateUrl: 'app/shared/base-profile/base-profile-view.html',
                controller: 'baseProfileController'
            },
            'header@root-profile': {
                templateUrl: 'app/shared/header-profile/header-profile-view.html',
                controller: 'headerProfileController'
            },
            'leftSideBar@root-profile': {
                templateUrl: 'app/shared/sidebar/left/left-side-bar-view.html',
                controller: 'leftSideBarController'
            },
            'rightSideBar@root-profile': {
                templateUrl: 'app/shared/sidebar/right/right-side-bar-view.html',
                controller: 'rightSideBarController'
            },
            'footer@root-profile': {
                templateUrl: 'app/shared/footer-profile/footer-profile-view.html',
                controller: 'footerProfileController'
            }

        } //END views
    }); //END state

    $stateProvider.state('profile', {
        url: '/profile',
        parent: 'root-profile',
        views: {
            'mainContent': {
                templateUrl: 'app/components/profile/profile-view.html',
                controller: 'profileController'
            }

        } //END views
    }); //END state

我有一个 base-profile-view.html,其中包含要注入的各个部分。他们每个人都有不同的模块。然后我将每个部分模块都包含在基本配置文件视图中

var baseProfileModule = angular.module("baseProfileModule", [
    'ui.router'
    , 'footerProfileModule'
    , 'headerProfileModule'
    , 'rightSideBarModule'
    , 'leftSideBarModule'
    , 'profileModule'
]);

然后我有另一个包含 baseProfileModule 的主模块:-

var baseModule = angular.module("baseModule", [
    'ui.router'
    ,'baseProfileModule'
    ,'baseSearchFrontModule'
]);

现在我想知道这是一种很好的做事方式,或者还有其他更好的方法。

4

0 回答 0