模块加载
1. 使用Angular-ui-router代替Angular-router
功能更强大的Angular路由器
2. 舍弃RequireJS
- 非ES6标准
- 代码侵入性太强
3. 使用onLazyLoad实现模块化加载
- 模块化加载任意文件
- 延迟html加载
4. 动态注册controller、service
/**
* 动态注册
* • 控制器
* • 过滤器
* • 指令
* • 服务
*/
app.register = {
controller: $controllerProvider.register,
directive: $compileProvider.directive,
filter: $filterProvider.register,
factory: $provide.factory,
service: $provide.service
};
5. 业务层提取
/**
* 定义Service
* 使用ES5
*/
function ApiService(){
/**
* 获取列表
*/
this.getList = function(){
this.apis = [
{subject : "111——这里是API的标题", description : "111——这是API的内容的内容的内容的内容", time : 1086468961},
{subject : "222——这里是API的标题", description : "222——这是API的内容的内容的内容的内容", time : 1086468961}
]
}
/**
* 添加API
*/
this.addApi = function(){
alert("ADD API");
}
}
/**
* 注册控制器
*/
app.register.controller("apiController", function($scope, $rootScope){
/**
* 将业务方法和属性赋予$scope
*/
ApiService.call($scope);
/**
* 业务层方法调用
*/
$scope.getList();
});