- Notifications
You must be signed in to change notification settings - Fork40
Load modules and components asynchronously for angular 1.x application.
License
NotificationsYou must be signed in to change notification settings
subchen/angular-async-loader
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
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
SupportcontrollerUrl/denpendencies
config inangular-ui-router
andangular-route
:
$stateProvider.state
$routeProvider.when
http://subchen.github.io/angular-async-loader/demo/
npm
npm install angular-async-loader
bower
bower install https://github.com/subchen/angular-async-loader.git
index.html
<scriptsrc="assets/requirejs/require.js"></script><scriptsrc="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){varangular=require('angular');varasyncLoader=require('angular-async-loader');require('angular-ui-router');varapp=angular.module('app',['ui.router']);// initialze app module for angular-async-loaderasyncLoader.configure(app);module.exports=app;});
app-routes.js
define(function(require){varapp=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 controllercontrollerUrl:'home/homeCtrl',controller:'homeCtrl'}).state('users',{url:'/users',templateUrl:'users/users.html',// new attribute for ajax load controllercontrollerUrl:'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 controllercontrollerUrl:'components/componentsCtrl',controller:'componentsCtrl'});}]);});
users/usersCtrl.js
define(function(require){varapp=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.varuserServices=app.get('usersService');$scope.userList=usersService.list();}]);});
components/componentsCtrl.js
define(function(require){varapp=require('../app');// dynamic load angular-ui-mask plugins for UIrequire('angular-ui-mask');app.useModule('ui.mask');// dynamic load ng-tags-input plugins for UIrequire('ng-tags-input');app.useModule('ngTagsInput');app.controller('componentsCtrl',['$scope',function($scope){ ......}]);});
git clone https://github.com/subchen/angular-async-loader.gitcd angular-async-loader./make.sh install./make.shtestopen browser http://localhost:3000/
Released under theApache 2 License.
Copyright 2015-2016 Guoqiang ChenLicensed 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.0Unless required by applicable law or agreed to in writing, softwaredistributed 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 andlimitations under the License.
About
Load modules and components asynchronously for angular 1.x application.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.