AngularJS的单页应用程序-如何建模
Single Page Apps with AngularJS - How to model?
我基于本教程构建了一个单页应用程序:
https://scotch.io/tutorials/single-page-apps-with-angularjs-routing-and-templating
这就是他们建议的文件结构:
- script.js <!-- stores all our angular code -->
- index.html <!-- main layout -->
- pages <!-- the pages that will be injected into the main layout -->
----- home.html
----- about.html
----- contact.html
关于html页面的部分非常简单——每个ng视图都有一个页面。凉的
但是script.js在我看来是一个糟糕的模型。
我真的应该把所有的js代码放在一个文件里吗?
在我看来,这不是最好的建模方法。
如果我的单页应用程序中有很多页面,会发生什么?
我会有一个很长的一个js文件,里面有所有的控制器。。
在angularjs中建模单页应用程序的最佳实践是什么?
谢谢!
// script.js
// create the module and name it scotchApp
// also include ngRoute for all our routing needs
var scotchApp = angular.module('scotchApp', ['ngRoute']);
// configure our routes
scotchApp.config(function($routeProvider) {
$routeProvider
// route for the home page
.when('/', {
templateUrl : 'pages/home.html',
controller : 'mainController'
})
// route for the about page
.when('/about', {
templateUrl : 'pages/about.html',
controller : 'aboutController'
})
// route for the contact page
.when('/contact', {
templateUrl : 'pages/contact.html',
controller : 'contactController'
});
});
// create the controller and inject Angular's $scope
scotchApp.controller('mainController', function($scope) {
// create a message to display in our view
$scope.message = 'Everyone come and see how good I look!';
});
scotchApp.controller('aboutController', function($scope) {
$scope.message = 'Look! I am an about page.';
});
scotchApp.controller('contactController', function($scope) {
$scope.message = 'Contact us! JK. This is just a demo.';
});
本详尽的样式指南建议您根据功能创建文件夹和组织应用程序。https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#application-结构
我建议阅读整个"应用程序结构"部分,它确实帮助我组织了我的角度项目
相关文章:
- 如何在类似Om的不可变应用程序状态下对关系数据进行建模
- 来自Svc的数据未建模到视图元素AngularJS中
- js:如何在每个it中对对象进行v建模's值
- 如何在Marionette.CompositeView中建模事件
- Rail对默认情况下隐藏在表单中的属性进行建模
- Kanga建模和显示图形失败
- 如何在角度 js 中对数据进行建模
- 通过 jquery 创建模态窗口
- 使用 React、Redux 和 Immutable.js 创建模态弹出窗口
- 主干.js对以前的方法不起作用进行建模
- 在Mongodb和NodeJS中建模博客和评级
- Circular Dependencies with RxJS. 对孢子进行建模
- 对具有节点和边的简单图形进行建模
- Ember:作为 CollectionView 的内容建模
- 如何在MongoDB中建模和查询办公时间(日期、时区、dst)
- 使用UML对JavaScript更改为HTML进行建模
- 如何用javascript建模字符串的最后一部分
- Canjs-扩展can.使用其他方法建模
- 如何在JavaScript中对此数据结构进行建模?(AngularJS)
- 尝试使用面向对象的javascript进行建模