Integration of Require. js and Angular. js
Require. js
For details, see:
First knowledge of Require. js
Decrypt Require. js
Angular. js
For details, see:
Angular. js: Love and hate
Integrate Require. js and Angular. js configurations
Configure angular. js in Requirejs.
Require-main.js
// Configure requirejs. config ({... paths: {'jquery ': 'libs/jquery-2.1.3/jquery. min', 'angular ': 'libs/angular-1.3.15/angular. min'}, shim: {'angular ': {deps: ['jquery'], exports: 'angular '}},...});
Create
Create an Angularjs application module.
Angular-app.js
// Create define (['angular '], function (angular) {return angular. module ('angularapp', []);});
Load and start
Load and start Angularjs through Requirejs
Require-bootstrap.js
GlobalConfig. requireScripts. unshift ('angular ', 'angularapp'); // load requirejs (GlobalConfig. requireScripts, function (angular) {// start $ (document ). ready (function () {angular. bootstrap (document, ['angularapp']) ;});
Page reference
<script src=/libs/require/require.js></script><script src=/require-main.js></script><script src=/require-bootstrap.js></script>
File references Angular. js
Introduce angularjs module through Requirejs dependency Injection
Define (['angularapp' // introduce angularjs], function (angularApp) {angularApp. factory ('loginservice', function () {var loginService ={}; loginService. login = function (data) {window. location. href = '/welcome';}; return loginService ;});});
Dynamically load js files through Requirejs