Created
December 18, 2014 12:35
-
-
Save LArVs/1592bcd504569f0e49a1 to your computer and use it in GitHub Desktop.
requirejs+angularjs+lazyload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title></title> | |
| </head> | |
| <body> | |
| <div ng-controller="controller1"> | |
| {{ name }} | |
| {{ name1 }} | |
| </div> | |
| <div ng-controller="controller2"> | |
| {{ name }} | |
| </div> | |
| <script src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.15/require.js"></script> | |
| <script> | |
| requirejs.config({ | |
| paths: { | |
| 'angular': 'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular', | |
| 'ng_lazy': 'https://cdn.rawgit.com/ocombe/ocLazyLoad/0.5.1/dist/ocLazyLoad', | |
| 'modules' : 'modules', | |
| }, | |
| shim: { | |
| 'angular': { | |
| exports: 'angular', | |
| }, | |
| 'ng_lazy': [ 'angular' ], | |
| 'modules': [ 'angular' ], | |
| 'module1': [ 'modules' ], | |
| 'module2': [ 'modules' ], | |
| }, | |
| // waitSeconds: 5, | |
| }); | |
| requirejs( [ 'angular', 'ng_lazy' ], function( angular ) { 'use strict'; | |
| angular.module( 'app', [ 'oc.lazyLoad', 'modules' ] ) | |
| .config( [ '$ocLazyLoadProvider', function( $ocLazyLoadProvider ) { | |
| $ocLazyLoadProvider.config({ | |
| asyncLoader : requirejs, | |
| loadedModules : [ 'app' ], | |
| }); | |
| }]); | |
| angular.bootstrap( document, [ 'app' ] ); | |
| console.log( 'app load' ); | |
| }); | |
| requirejs( [ 'module1', 'module2' ], function( angular ) { 'use strict'; | |
| console.log( 'modules load' ); | |
| }); | |
| </script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| angular.module( 'modules' ) | |
| .controller('controller1', | |
| [ '$scope', | |
| function($scope){ | |
| $scope.name = 'controller1'; | |
| $scope.name1 = 'controller1_name1'; | |
| }]) | |
| ; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| angular.module( 'modules' ) | |
| .controller('controller2', | |
| [ '$scope', | |
| function($scope){ | |
| $scope.name = 'controller2'; | |
| }]) | |
| ; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| angular.module( 'modules', [] ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment