• Stars
    star
    120
  • Rank 295,983 (Top 6 %)
  • Language
    JavaScript
  • Created about 11 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A lazyload service for angular projects, only load-on-demand, support seajs/requirejs/custom.

angular-lazyload

NOT CURRENTLY MAINTAINED, use ocLazyLoad or angular2

a lazyload service for angular projects, only load-on-demand, support seajs/requirejs/custom.

按需加载AngularJS模块, 支持Sea.jsRequireJS


下载 (or 压缩版) | 使用指南 | 基本原理 | TODO/贡献代码 | 示例使用说明


使用指南

(1) 安装

(2) 在你的index.html中引入angular-lazyload

  <!-- 实际项目中用bower安装到本地 -->
  <script src="components/seajs/sea.js" id="seajsnode"></script>
  <script src="components/angular/angular.js"></script>
  <script src="components/angular-route/angular-route.js"></script>
  
  <!-- Step1: include js -->
  <script src="../../src/angular-lazyload.js"></script>

(3) 在你的启动文件里面, 手动启动bootstrap。

  //Step2: bootstrap youself
  seajs.use(['app'], function(app){
    angular.bootstrap(document, ['app']);
  });

(3) 添加angular-lazyload为你的主模块的依赖中。

  //Step3: add 'angular-lazyload' to your main module's list of dependencies
  var app = angular.module('app', ['angular-lazyload', 'ngRoute']);

(4)app.run里进行初始化。

  app.run(['$lazyload', function($lazyload){
    //Step5: init lazyload & hold refs
    $lazyload.init(app);
    app.register = $lazyload.register;
  }]);

(5) 路由映射, 添加controllerUrl

  //Step4: add `controllerUrl` to your route item config
  $routeProvider
    .when('/test/a', {
      controller: 'testACtrl',
      controllerUrl: 'modules/module1/testACtrl.js',
      templateUrl: 'modules/module1/testA.tpl.html'
    })
  }

(6) 在你的模块里进行注册controller。

  //Step6: use `app.register` to register controller/service/directive/filter
  app.register.controller('testACtrl', ['$scope', function($scope){
    ...
  }]);

基本原理

  • 通过routeresolve做hack点
  • config期保存register的引用
  • 监听$routeChangeStart事件, 动态添加一个resolve
  • resolve里面通过seajs去动态加载模块,并动态注册

TODO

  • 添加测试的示例, 参考seajs/seajs#874
  • 欢迎PullRequest贡献代码

示例使用说明

  1. 安装nodejs -- 下载对应版本并安装
  2. 安装grunt -- 命令行下执行: npm install -g grunt-cli (不包含符号` ,下同)
  3. 安装bower -- 命令行下执行: npm install -g bower (不包含符号` ,下同)
  4. 安装依赖库 -- 命令行到项目根目录,执行 npm install
  5. 安装Web类库 -- 命令行到example目录,执行 bower install
  6. 运行示例 -- 命令行执行 grunt server, 将自动打开浏览器显示首页
  7. 若参与开发则 -- 命令行执行 grunt dev, 欢迎通过PullRequest贡献代码

More Repositories

1

blog

天猪部落阁 http://atian25.github.io
HTML
1,587
star
2

yuque-exporter

export yuque to local markdown
TypeScript
313
star
3

node-cookbook

《Node.js 从小工坊走向企业级开发》相关示例源码(尚未完成)
JavaScript
69
star
4

vscode-copy-syntax

copy your code with syntax highlight to clipboard, can be used at your slide.
TypeScript
27
star
5

egg-remote-config

workaround for egg remote config
JavaScript
22
star
6

alfred-plugin-projj

Alfred plugin for https://github.com/popomore/projj
JavaScript
13
star
7

yadan

showcase for egg framework
JavaScript
11
star
8

atian25.github.io

该仓库仅用于域名使用, 相关内容迁移到 https://github.com/atian25/blog , 敬请移步.
HTML
7
star
9

angular-fis-showcase

showcase for angular + fis
JavaScript
7
star
10

egg-showcase-ts

showcase for egg + ts
5
star
11

supermocker

provide dynamic mocker middleware
JavaScript
4
star
12

vuepress-plugin-yuque-deploy

deploy your vuepress markdown to https://yuque.com
JavaScript
4
star
13

npm-release-notifier

monitor npm package release
JavaScript
4
star
14

egg-showcase

用于 egg 的 issue 解答示例
JavaScript
4
star
15

webcontainer-egg

Created with StackBlitz ⚡️
JavaScript
3
star
16

artus-common-bin

TypeScript
3
star
17

alfred-plugin-bob

alfred plugin for translate with [bob](https://ripperhe.gitee.io/bob)
3
star
18

npm-depended-analysis

JavaScript
3
star
19

node-bug-report

JavaScript
3
star
20

leaks-detector

JavaScript
3
star
21

node-snippets

just some snippets
JavaScript
2
star
22

esm-snippet

snippet for esm project
JavaScript
2
star
23

vscode-debug-brk

issue report for vscode debug egg
JavaScript
2
star
24

npm-showcase-utils

utils for npm-showcase
JavaScript
2
star
25

egg-showcase-progressive

progressive showcase for egg
2
star
26

node-unittest-showcase

TodoMVC - Node.js Showcase
TypeScript
2
star
27

npm-showcase-boilerplate

boilerplate for npm showcase
JavaScript
1
star
28

katacoda-scenarios

Katacoda Scenarios
JavaScript
1
star
29

egg-gitstats

git stats for egg project
Python
1
star
30

mocha-codemod

JavaScript
1
star
31

egg-meet-ts

showcase project to discuss how to enjoy intellisense by ts at https://eggjs.org project
JavaScript
1
star
32

nodejs-template

GitHub repository template
Dockerfile
1
star
33

dotfiles

Dotfiles for Github Codespaces
Shell
1
star
34

genshin-voice

scraping genshin voices
TypeScript
1
star
35

multipart-async

modern multipart parser with async iterator, base on busboy
JavaScript
1
star
36

monorepo-test

JavaScript
1
star
37

trash-bug-report

JavaScript
1
star
38

npm-showcase

just a showcase for npm
JavaScript
1
star
39

atian25

1
star
40

require-resolve-trouble

1
star
41

npm-packages-should-say-goodbye

To those npm packages, thanks for accompanying us so long. farewell~
1
star
42

github-webhook-vercel

TypeScript
1
star
43

c8-test-2

TypeScript
1
star
44

c8-test

JavaScript
1
star