• Stars
    star
    136
  • Rank 267,670 (Top 6 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created about 9 years ago
  • Updated over 7 years ago

Reviews

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

Repository Details

Load modules and components asynchronously for angular 1.x application.

NPM Repo License

angular-async-loader

Load modules and components asynchronously for angular 1.x application.

Support load angular modules:

  • app.useModule(name)

Support load angular components:

  • app.controller
  • app.services
  • app.filter
  • app.directive
  • app.value
  • app.constant
  • app.provider
  • app.decorator

Support following amd/cmd loaders:

  • Require.js
  • Sea.js
  • System.js

Support controllerUrl/denpendencies config in angular-ui-router and angular-route:

  • $stateProvider.state
  • $routeProvider.when

Demo

http://subchen.github.io/angular-async-loader/demo/

Installation

npm

npm install angular-async-loader

bower

bower install https://github.com/subchen/angular-async-loader.git

Usage

index.html

<script src="assets/requirejs/require.js"></script>
<script src="bootstrap.js"></script>

bootstrap.js

require.config({
    baseUrl: '/',
    paths: {
        'angular': 'assets/angular/angular.min',
        'angular-ui-router': 'assets/angular-ui-router/release/angular-ui-router.min',
        'angular-async-loader': 'assets/angular-async-loader/angular-async-loader.min',
        'angular-ui-mask': 'assets/angular-ui-mask/dist/mask.min',
        'ng-tags-input': 'assets/ng-tags-input/build/ng-tags-input.min'
    },
    shim: {
        'angular': {exports: 'angular'},
        'angular-ui-router': {deps: ['angular']}
    }
});

require(['angular', './app-routes'], function (angular) {
    angular.element(document).ready(function () {
        angular.bootstrap(document, ['app']);
        angular.element(document).find('html').addClass('ng-app');
    });
});

app.js

define(function (require, exports, module) {
    var angular = require('angular');
    var asyncLoader = require('angular-async-loader');

    require('angular-ui-router');

    var app = angular.module('app', ['ui.router']);

    // initialze app module for angular-async-loader
    asyncLoader.configure(app);

    module.exports = app;
});

app-routes.js

define(function (require) {
    var app = require('./app');

    app.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
        $urlRouterProvider.otherwise('/home');

        $stateProvider
            .state('home', {
                url: '/home',
                templateUrl: 'home/home.html',
                // new attribute for ajax load controller
                controllerUrl: 'home/homeCtrl',
                controller: 'homeCtrl'
            })
            .state('users', {
                url: '/users',
                templateUrl: 'users/users.html',
                // new attribute for ajax load controller
                controllerUrl: 'users/usersCtrl',
                controller: 'usersCtrl',
                // support to load more controllers, services, filters, ...
                dependencies: ['services/usersService']
            })
            .state('components', {
                url: '/components',
                templateUrl: 'components/components.html',
                // new attribute for ajax load controller
                controllerUrl: 'components/componentsCtrl',
                controller: 'componentsCtrl'
            });
    }]);
});

users/usersCtrl.js

define(function (require) {
    var app = require('../app');

    // dynamic load services here or add into dependencies of ui-router state config
    // require('../services/usersService');

    app.controller('usersCtrl', ['$scope', function ($scope) {
        // shortcut to get angular injected service.
        var userServices = app.get('usersService');
        $scope.userList = usersService.list();
    }]);

});

components/componentsCtrl.js

define(function (require) {
    var app = require('../app');

    // dynamic load angular-ui-mask plugins for UI
    require('angular-ui-mask');
    app.useModule('ui.mask');

    // dynamic load ng-tags-input plugins for UI
    require('ng-tags-input');
    app.useModule('ngTagsInput');

    app.controller('componentsCtrl', ['$scope', function ($scope) {
        ......
    }]);

});

Build from Source

git clone https://github.com/subchen/angular-async-loader.git

cd angular-async-loader

./make.sh install
./make.sh test

open browser http://localhost:3000/

License

Released under the Apache 2 License.

Copyright 2015-2016 Guoqiang Chen

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

More Repositories

1

jetbrick-template-2x

Template Engine for Java
Java
371
star
2

frep

Generate file using template from environment, arguments, json/yaml/toml config files
Go
154
star
3

javadoc.chm

This software generates an Microsoft HTML Help(CHM) from generic javadoc style API documents
Java
143
star
4

jetbrick-template-1x

Java template engine, quickly and easily.
Java
68
star
5

go-xmldom

XML DOM processing for Golang, supports xpath query
Go
44
star
6

go-trylock

TryLock support on read-write lock for Golang
Go
33
star
7

jetbrick-webmvc

jetbrick web mvc framework
Java
25
star
8

centos-7-kickstart

build a centos 7 iso/ovf/ova with kickstart
Shell
21
star
9

jetbrick-commons

jetbrick utility classes
Java
21
star
10

go-log

Simple and configurable Logging in Go, with level, formatters and writers
Go
14
star
11

go-cli

A full-featured and easy to use command-line package
Go
13
star
12

jetbrick-template-2x-samples

Samples for jetbrick-template-2x
Java
11
star
13

jetbrick-template-1x-samples

The samples for jetbrick-template integrated with webmvc
Java
9
star
14

jetbrick-ioc

IoC framwork for jetbrick
Java
7
star
15

jetbrick-webmvc-samples

Samples for jetbrick-webmvc
Java
6
star
16

go-stack

Common utility functions for Golang
Go
6
star
17

go-tableify

Pretty console printing of tabular data
Go
5
star
18

go-curl

A Go HTTP client library for creating and sending API requests
Go
5
star
19

jetbrick-orm

Object-relational mapping framework
Java
4
star
20

jetbrick-all-1x

A full-stack framework written with java
Java
4
star
21

gls

A goroutine-local storage for golang
Go
3
star
22

subchen.github.io

WebSite for subchen.github.com
HTML
3
star
23

ovfenv-installer

Configure networking from vSphere ovfEnv properties
Go
3
star
24

homebrew-tap

Tools of macOS Homebrew Packages
Ruby
2
star
25

snack

Generic functional library for javascript/node.js
JavaScript
2
star
26

snack-string

Generic string functional library for javascript/node.js
JavaScript
2
star
27

dev-box

A development box deployer, Support macOS, CentOS and Ubuntu.
Shell
2
star
28

shaft

Java simple database operation framework
Java
2
star
29

snack-cli

command-line interfaces for node.js
JavaScript
2
star
30

bintray-cli

Command line for api.bintray.com
1
star
31

jetbrick-template-shiro

Shiro tag extension for jetbrick-template
Java
1
star
32

jetbrick-website-app

website for http://subchen.github.io/
Java
1
star
33

jetbrick-extension

jetbrick extension modules
Java
1
star
34

jetbrick-jdbclog

jdbc logger for jetbrick
Java
1
star
35

jetbrick-ioc-spring

Spring intergrate for Jetbrick IoC
Java
1
star