1

我是新来的角的js大型Angular应用程序的项目结构?

我要创造我的项目结构,这样

​​

这里的核心,试验不同的模块(NG-APP)

我配置一样这里

app.js angular.module( 'mainapp',[ 'mainapp.core', 'mainapp.test'])

core.app.js angular.module( 'mainapp.core',[])

test.app.js angular.module( 'mainapp.test',[])

在这里我gettiing问题,我的核心模块状态不能正常工作。我使用$ staeprovider(ui-views)进行路由。

例如

core.config.routes.js

angular.module('mainapp.core').config(function($stateProvider, 
     $urlRouterProvider) { 

$stateProvider 
    .state('core', { 
     url: '/core', 
     templateUrl: 'modules/core/views/core.html', 

    }) 
    .state('core.sidebar ', { 
     url: '^/sidebar ', 
     templateUrl: 'modules/core/views/core.sidebar .html' 
    }) 
    }); 

test.config.routes.js

angular.module('mainapp.test').config(function($stateProvider, 
     $urlRouterProvider) { 

$stateProvider 

    .state('core.sidebar .test', { 
     url: '^/test', 
     templateUrl: 'modules/core/views/test.html' 
    }) 
    }); 

我的HTML页面

的index.html

<div ng-app="mainapp"> 
     <div ui-view= ""></div> 
    </div> 

core.html

` <div> 
      <h1>I am designing jeader Here. it goes on tp of page</h1> 
      <div ui-view></div> 
     </div>` 

core.sidebar的.html

`<div> 
    <h2>It goes left side</h2> 

     <h1>I am designing sidebar Here</h1> 

     <div ui-view></div> 
    </div>` 

,直到这工作的罚款。 heaser,代尔栏加载$状态下core.sidebar

在这里我得到的问题是”不工作 的test.html

<div> 
     <h1>I am designing middle content Here</h1> 

    </div> 

请任何一个可以帮助我解决这个问题,建立更好的项目结构方法

回答

0

我建议你看他们如何推荐项目结构的Angular Style Guide。https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#application-structure-lift-principle

我真的很喜欢他们的推荐使用LIFT方法:

  • 定位我们的代码很容易
  • 一目了然
  • 扁平结构识别码,只要我们能
  • 尝试保持干燥(不要重复自己)或T-DRY

本着这种精神,您可能只需要一个模块文件夹,然后使用文件命名约定来保持组织性。在我的项目中,我这样做并使用ng结构前缀。例如:

  • nx.core
    • controller.header
    • controller.footer
    • controller.app
    • 路由
  • nx.admin
    • 路线
    • controller.admin
    • directive.blah

这样做,我能够同时实现组织扁平化,以及我需要用眼睛快速过滤,哪些文件。那么唯一的缺点是如果你在你的IDE中使用快捷方式来快速打开文件,你通常认为在FindingsController不通过像前缀controller.Findings。我的2¢