Angular技术库
  • 简介
  • 研究热点
    • 单页面登录
    • 单页面服务器渲染
  • 项目实战
    • 目录结构
    • 模块开发流程
    • 公共模块编辑
    • UI使用
    • 工具库
      • util模块
      • filter模块
    • 表单验证
  • 整体框架
    • 环境搭建
      • Windows
      • MAC Linux
    • 示例项目
    • 开发调试
      • 编译JS
      • 编译CSS
      • 编译HTML
      • 编译Bower
      • 服务器启动
      • 与后端服务通讯
    • Gulp文档
      • Gulp API
      • 插件列表
      • Gulp构建
    • Gulp文档
    • 示例项目
  • Angular文档
    • 指令
    • 引导
    • 单页面
    • 基于requireJS和angularJS的前端技术架构
    • 数据共享
    • 模块加载
    • 事件循环
  • SASS文档
    • SASS特性
  • ES6文档
    • ECMAScript前导
    • ECMAScript6特性介绍
    • ES6特性筛选
  • JavaScript文档
    • 匿名函数定义
    • Function
      • 原生prototype
      • 自定义prototype
  • RequireJS
  • Node文档
  • 架构师
  • 时间轴
    • 2016-07-13
    • 2016-06-21
    • 2016-06-14
    • 2016-06-07
    • 2016-05-31
Powered by GitBook
On this page
  • 1. 使用Angular-ui-router代替Angular-router
  • 2. 舍弃RequireJS
  • 3. 使用onLazyLoad实现模块化加载
  • 4. 动态注册controller、service
  • 5. 业务层提取
  1. Angular文档

模块加载

1. 使用Angular-ui-router代替Angular-router

功能更强大的Angular路由器

2. 舍弃RequireJS

  1. 非ES6标准

  2. 代码侵入性太强

3. 使用onLazyLoad实现模块化加载

  1. 模块化加载任意文件

  2. 延迟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();
});
Previous数据共享Next事件循环

Last updated 7 years ago