app.js
file is used to initialize the loading and configuration of the application.index.html
with the connected JS-files in the desired order.index-async.html
, which uses angular-loader.js or third-party loaders, to load dependencies asynchronously.bower.json
: { "name": "AngularJS + RequireJS Example", "version": "0.1", "main": "index.html", "ignore": [ "**/.*", "libs" ], "dependencies": { "angular": "latest", "requirejs": "latest", "requirejs-domready": "latest" } }
.bowerrc
file next to bower.json
and run bower install
. Now all the necessary dependencies are in the libs
directory.index.html
and remove all tags . , ?
. , ?
. , ?
, which will load the RequireJs library, and instruct it to look for the configuration in the js/main.js
file specified in the data-main
attribute of the tag :
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>My AngularJS AngularJS + RequireJS App</title> <link rel="stylesheet" href="css/app.css"> </head> <body> <ul class="menu"> <li><a href="#/view1">view1</a></li> <li><a href="#/view2">view2</a></li> </ul> <div data-ng-view></div> <div>Angular Require seed app: v<span app-version></span></div> <script src="lib/requirejs/require.js" data-main="js/main.js"></script> </body> </html>
. index.html
, .
main.js
RequireJS.
require.config({ // paths: { 'domReady': '../lib/requirejs-domready/domReady', 'angular': '../lib/angular/angular' }, // angular AMD , angular shim: { 'angular': { exports: 'angular' } }, // deps: ['./bootstrap'] });
?
paths
. AngularJs ( shim ). , bootstrap.js
.
bootstrap.js
AngularJs, bootstrap.js
( , ng-app
HTML ). routes.js
, , .
, ,
angular->app->routes
: AngularJs (app) (routes).
/** * bootstraps angular onto the window.document node */ define([ 'require', 'angular', 'app', 'routes' ], function (require, ng) { 'use strict'; require(['domReady!'], function (document) { ng.bootstrap(document, ['app']); }); });
domReady
, , DOM . , app.js
, .
app.js
app.js
.
define([ 'angular', './controllers/index', './directives/index', './filters/index', './services/index' ], function (ng) { 'use strict'; return ng.module('app', [ 'app.services', 'app.controllers', 'app.filters', 'app.directives' ]); });
: (controllers), (directives), (filters), (services). , .
routes.js
(routes) . ( ).
define(['./app'], function (app) { 'use strict'; return app.config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/view1', { templateUrl: 'partials/partial1.html', controller: 'MyCtrl1' }); $routeProvider.when('/view2', { templateUrl: 'partials/partial2.html', controller: 'MyCtrl2' }); $routeProvider.otherwise({ redirectTo: '/view1' }); }]); });
:
app.controllers
.
controllers/module.js
define(['angular'], function (ng) { 'use strict'; return ng.module('app.controllers', []); });
(. )
controllers/index.js
define, . module.js ( ). . RequireJs .
define([ './my-ctrl-1', './my-ctrl-2' ], function () {});
controllers/my-ctrl-1.js
app.controllers
. :
define(['./module'], function (controllers) { 'use strict'; controllers.controller('MyCtrl1', [function ($scope) {}]); });
, ./module.js
.
:
. AngularJs RequireJs. , .
:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>My AngularJS AngularJS + RequireJS App</title> <link rel="stylesheet" href="css/app.css"> </head> <body> <ul class="menu"> <li><a href="#/view1">view1</a></li> <li><a href="#/view2">view2</a></li> </ul> <div data-ng-view></div> <div>Angular Require seed app: v<span app-version></span></div> <script src="lib/requirejs/require.js" data-main="js/main.js"></script> </body> </html>
. index.html
, .
main.js
RequireJS.
require.config({ // paths: { 'domReady': '../lib/requirejs-domready/domReady', 'angular': '../lib/angular/angular' }, // angular AMD , angular shim: { 'angular': { exports: 'angular' } }, // deps: ['./bootstrap'] });
?
paths
. AngularJs ( shim ). , bootstrap.js
.
bootstrap.js
AngularJs, bootstrap.js
( , ng-app
HTML ). routes.js
, , .
, ,
angular->app->routes
: AngularJs (app) (routes).
/** * bootstraps angular onto the window.document node */ define([ 'require', 'angular', 'app', 'routes' ], function (require, ng) { 'use strict'; require(['domReady!'], function (document) { ng.bootstrap(document, ['app']); }); });
domReady
, , DOM . , app.js
, .
app.js
app.js
.
define([ 'angular', './controllers/index', './directives/index', './filters/index', './services/index' ], function (ng) { 'use strict'; return ng.module('app', [ 'app.services', 'app.controllers', 'app.filters', 'app.directives' ]); });
: (controllers), (directives), (filters), (services). , .
routes.js
(routes) . ( ).
define(['./app'], function (app) { 'use strict'; return app.config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/view1', { templateUrl: 'partials/partial1.html', controller: 'MyCtrl1' }); $routeProvider.when('/view2', { templateUrl: 'partials/partial2.html', controller: 'MyCtrl2' }); $routeProvider.otherwise({ redirectTo: '/view1' }); }]); });
:
app.controllers
.
controllers/module.js
define(['angular'], function (ng) { 'use strict'; return ng.module('app.controllers', []); });
(. )
controllers/index.js
define, . module.js ( ). . RequireJs .
define([ './my-ctrl-1', './my-ctrl-2' ], function () {});
controllers/my-ctrl-1.js
app.controllers
. :
define(['./module'], function (controllers) { 'use strict'; controllers.controller('MyCtrl1', [function ($scope) {}]); });
, ./module.js
.
:
. AngularJs RequireJs. , .
:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>My AngularJS AngularJS + RequireJS App</title> <link rel="stylesheet" href="css/app.css"> </head> <body> <ul class="menu"> <li><a href="#/view1">view1</a></li> <li><a href="#/view2">view2</a></li> </ul> <div data-ng-view></div> <div>Angular Require seed app: v<span app-version></span></div> <script src="lib/requirejs/require.js" data-main="js/main.js"></script> </body> </html>
. index.html
, .
main.js
RequireJS.
require.config({ // paths: { 'domReady': '../lib/requirejs-domready/domReady', 'angular': '../lib/angular/angular' }, // angular AMD , angular shim: { 'angular': { exports: 'angular' } }, // deps: ['./bootstrap'] });
?
paths
. AngularJs ( shim ). , bootstrap.js
.
bootstrap.js
AngularJs, bootstrap.js
( , ng-app
HTML ). routes.js
, , .
, ,
angular->app->routes
: AngularJs (app) (routes).
/** * bootstraps angular onto the window.document node */ define([ 'require', 'angular', 'app', 'routes' ], function (require, ng) { 'use strict'; require(['domReady!'], function (document) { ng.bootstrap(document, ['app']); }); });
domReady
, , DOM . , app.js
, .
app.js
app.js
.
define([ 'angular', './controllers/index', './directives/index', './filters/index', './services/index' ], function (ng) { 'use strict'; return ng.module('app', [ 'app.services', 'app.controllers', 'app.filters', 'app.directives' ]); });
: (controllers), (directives), (filters), (services). , .
routes.js
(routes) . ( ).
define(['./app'], function (app) { 'use strict'; return app.config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/view1', { templateUrl: 'partials/partial1.html', controller: 'MyCtrl1' }); $routeProvider.when('/view2', { templateUrl: 'partials/partial2.html', controller: 'MyCtrl2' }); $routeProvider.otherwise({ redirectTo: '/view1' }); }]); });
:
app.controllers
.
controllers/module.js
define(['angular'], function (ng) { 'use strict'; return ng.module('app.controllers', []); });
(. )
controllers/index.js
define, . module.js ( ). . RequireJs .
define([ './my-ctrl-1', './my-ctrl-2' ], function () {});
controllers/my-ctrl-1.js
app.controllers
. :
define(['./module'], function (controllers) { 'use strict'; controllers.controller('MyCtrl1', [function ($scope) {}]); });
, ./module.js
.
:
. AngularJs RequireJs. , .
:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>My AngularJS AngularJS + RequireJS App</title> <link rel="stylesheet" href="css/app.css"> </head> <body> <ul class="menu"> <li><a href="#/view1">view1</a></li> <li><a href="#/view2">view2</a></li> </ul> <div data-ng-view></div> <div>Angular Require seed app: v<span app-version></span></div> <script src="lib/requirejs/require.js" data-main="js/main.js"></script> </body> </html>
. index.html
, .
main.js
RequireJS.
require.config({ // paths: { 'domReady': '../lib/requirejs-domready/domReady', 'angular': '../lib/angular/angular' }, // angular AMD , angular shim: { 'angular': { exports: 'angular' } }, // deps: ['./bootstrap'] });
?
paths
. AngularJs ( shim ). , bootstrap.js
.
bootstrap.js
AngularJs, bootstrap.js
( , ng-app
HTML ). routes.js
, , .
, ,
angular->app->routes
: AngularJs (app) (routes).
/** * bootstraps angular onto the window.document node */ define([ 'require', 'angular', 'app', 'routes' ], function (require, ng) { 'use strict'; require(['domReady!'], function (document) { ng.bootstrap(document, ['app']); }); });
domReady
, , DOM . , app.js
, .
app.js
app.js
.
define([ 'angular', './controllers/index', './directives/index', './filters/index', './services/index' ], function (ng) { 'use strict'; return ng.module('app', [ 'app.services', 'app.controllers', 'app.filters', 'app.directives' ]); });
: (controllers), (directives), (filters), (services). , .
routes.js
(routes) . ( ).
define(['./app'], function (app) { 'use strict'; return app.config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/view1', { templateUrl: 'partials/partial1.html', controller: 'MyCtrl1' }); $routeProvider.when('/view2', { templateUrl: 'partials/partial2.html', controller: 'MyCtrl2' }); $routeProvider.otherwise({ redirectTo: '/view1' }); }]); });
:
app.controllers
.
controllers/module.js
define(['angular'], function (ng) { 'use strict'; return ng.module('app.controllers', []); });
(. )
controllers/index.js
define, . module.js ( ). . RequireJs .
define([ './my-ctrl-1', './my-ctrl-2' ], function () {});
controllers/my-ctrl-1.js
app.controllers
. :
define(['./module'], function (controllers) { 'use strict'; controllers.controller('MyCtrl1', [function ($scope) {}]); });
, ./module.js
.
:
. AngularJs RequireJs. , .
:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>My AngularJS AngularJS + RequireJS App</title> <link rel="stylesheet" href="css/app.css"> </head> <body> <ul class="menu"> <li><a href="#/view1">view1</a></li> <li><a href="#/view2">view2</a></li> </ul> <div data-ng-view></div> <div>Angular Require seed app: v<span app-version></span></div> <script src="lib/requirejs/require.js" data-main="js/main.js"></script> </body> </html>
. index.html
, .
main.js
RequireJS.
require.config({ // paths: { 'domReady': '../lib/requirejs-domready/domReady', 'angular': '../lib/angular/angular' }, // angular AMD , angular shim: { 'angular': { exports: 'angular' } }, // deps: ['./bootstrap'] });
?
paths
. AngularJs ( shim ). , bootstrap.js
.
bootstrap.js
AngularJs, bootstrap.js
( , ng-app
HTML ). routes.js
, , .
, ,
angular->app->routes
: AngularJs (app) (routes).
/** * bootstraps angular onto the window.document node */ define([ 'require', 'angular', 'app', 'routes' ], function (require, ng) { 'use strict'; require(['domReady!'], function (document) { ng.bootstrap(document, ['app']); }); });
domReady
, , DOM . , app.js
, .
app.js
app.js
.
define([ 'angular', './controllers/index', './directives/index', './filters/index', './services/index' ], function (ng) { 'use strict'; return ng.module('app', [ 'app.services', 'app.controllers', 'app.filters', 'app.directives' ]); });
: (controllers), (directives), (filters), (services). , .
routes.js
(routes) . ( ).
define(['./app'], function (app) { 'use strict'; return app.config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/view1', { templateUrl: 'partials/partial1.html', controller: 'MyCtrl1' }); $routeProvider.when('/view2', { templateUrl: 'partials/partial2.html', controller: 'MyCtrl2' }); $routeProvider.otherwise({ redirectTo: '/view1' }); }]); });
:
app.controllers
.
controllers/module.js
define(['angular'], function (ng) { 'use strict'; return ng.module('app.controllers', []); });
(. )
controllers/index.js
define, . module.js ( ). . RequireJs .
define([ './my-ctrl-1', './my-ctrl-2' ], function () {});
controllers/my-ctrl-1.js
app.controllers
. :
define(['./module'], function (controllers) { 'use strict'; controllers.controller('MyCtrl1', [function ($scope) {}]); });
, ./module.js
.
:
. AngularJs RequireJs. , .
:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>My AngularJS AngularJS + RequireJS App</title> <link rel="stylesheet" href="css/app.css"> </head> <body> <ul class="menu"> <li><a href="#/view1">view1</a></li> <li><a href="#/view2">view2</a></li> </ul> <div data-ng-view></div> <div>Angular Require seed app: v<span app-version></span></div> <script src="lib/requirejs/require.js" data-main="js/main.js"></script> </body> </html>
. index.html
, .
main.js
RequireJS.
require.config({ // paths: { 'domReady': '../lib/requirejs-domready/domReady', 'angular': '../lib/angular/angular' }, // angular AMD , angular shim: { 'angular': { exports: 'angular' } }, // deps: ['./bootstrap'] });
?
paths
. AngularJs ( shim ). , bootstrap.js
.
bootstrap.js
AngularJs, bootstrap.js
( , ng-app
HTML ). routes.js
, , .
, ,
angular->app->routes
: AngularJs (app) (routes).
/** * bootstraps angular onto the window.document node */ define([ 'require', 'angular', 'app', 'routes' ], function (require, ng) { 'use strict'; require(['domReady!'], function (document) { ng.bootstrap(document, ['app']); }); });
domReady
, , DOM . , app.js
, .
app.js
app.js
.
define([ 'angular', './controllers/index', './directives/index', './filters/index', './services/index' ], function (ng) { 'use strict'; return ng.module('app', [ 'app.services', 'app.controllers', 'app.filters', 'app.directives' ]); });
: (controllers), (directives), (filters), (services). , .
routes.js
(routes) . ( ).
define(['./app'], function (app) { 'use strict'; return app.config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/view1', { templateUrl: 'partials/partial1.html', controller: 'MyCtrl1' }); $routeProvider.when('/view2', { templateUrl: 'partials/partial2.html', controller: 'MyCtrl2' }); $routeProvider.otherwise({ redirectTo: '/view1' }); }]); });
:
app.controllers
.
controllers/module.js
define(['angular'], function (ng) { 'use strict'; return ng.module('app.controllers', []); });
(. )
controllers/index.js
define, . module.js ( ). . RequireJs .
define([ './my-ctrl-1', './my-ctrl-2' ], function () {});
controllers/my-ctrl-1.js
app.controllers
. :
define(['./module'], function (controllers) { 'use strict'; controllers.controller('MyCtrl1', [function ($scope) {}]); });
, ./module.js
.
:
. AngularJs RequireJs. , .
:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>My AngularJS AngularJS + RequireJS App</title> <link rel="stylesheet" href="css/app.css"> </head> <body> <ul class="menu"> <li><a href="#/view1">view1</a></li> <li><a href="#/view2">view2</a></li> </ul> <div data-ng-view></div> <div>Angular Require seed app: v<span app-version></span></div> <script src="lib/requirejs/require.js" data-main="js/main.js"></script> </body> </html>
. index.html
, .
main.js
RequireJS.
require.config({ // paths: { 'domReady': '../lib/requirejs-domready/domReady', 'angular': '../lib/angular/angular' }, // angular AMD , angular shim: { 'angular': { exports: 'angular' } }, // deps: ['./bootstrap'] });
?
paths
. AngularJs ( shim ). , bootstrap.js
.
bootstrap.js
AngularJs, bootstrap.js
( , ng-app
HTML ). routes.js
, , .
, ,
angular->app->routes
: AngularJs (app) (routes).
/** * bootstraps angular onto the window.document node */ define([ 'require', 'angular', 'app', 'routes' ], function (require, ng) { 'use strict'; require(['domReady!'], function (document) { ng.bootstrap(document, ['app']); }); });
domReady
, , DOM . , app.js
, .
app.js
app.js
.
define([ 'angular', './controllers/index', './directives/index', './filters/index', './services/index' ], function (ng) { 'use strict'; return ng.module('app', [ 'app.services', 'app.controllers', 'app.filters', 'app.directives' ]); });
: (controllers), (directives), (filters), (services). , .
routes.js
(routes) . ( ).
define(['./app'], function (app) { 'use strict'; return app.config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/view1', { templateUrl: 'partials/partial1.html', controller: 'MyCtrl1' }); $routeProvider.when('/view2', { templateUrl: 'partials/partial2.html', controller: 'MyCtrl2' }); $routeProvider.otherwise({ redirectTo: '/view1' }); }]); });
:
app.controllers
.
controllers/module.js
define(['angular'], function (ng) { 'use strict'; return ng.module('app.controllers', []); });
(. )
controllers/index.js
define, . module.js ( ). . RequireJs .
define([ './my-ctrl-1', './my-ctrl-2' ], function () {});
controllers/my-ctrl-1.js
app.controllers
. :
define(['./module'], function (controllers) { 'use strict'; controllers.controller('MyCtrl1', [function ($scope) {}]); });
, ./module.js
.
:
. AngularJs RequireJs. , .
:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>My AngularJS AngularJS + RequireJS App</title> <link rel="stylesheet" href="css/app.css"> </head> <body> <ul class="menu"> <li><a href="#/view1">view1</a></li> <li><a href="#/view2">view2</a></li> </ul> <div data-ng-view></div> <div>Angular Require seed app: v<span app-version></span></div> <script src="lib/requirejs/require.js" data-main="js/main.js"></script> </body> </html>
. index.html
, .
main.js
RequireJS.
require.config({ // paths: { 'domReady': '../lib/requirejs-domready/domReady', 'angular': '../lib/angular/angular' }, // angular AMD , angular shim: { 'angular': { exports: 'angular' } }, // deps: ['./bootstrap'] });
?
paths
. AngularJs ( shim ). , bootstrap.js
.
bootstrap.js
AngularJs, bootstrap.js
( , ng-app
HTML ). routes.js
, , .
, ,
angular->app->routes
: AngularJs (app) (routes).
/** * bootstraps angular onto the window.document node */ define([ 'require', 'angular', 'app', 'routes' ], function (require, ng) { 'use strict'; require(['domReady!'], function (document) { ng.bootstrap(document, ['app']); }); });
domReady
, , DOM . , app.js
, .
app.js
app.js
.
define([ 'angular', './controllers/index', './directives/index', './filters/index', './services/index' ], function (ng) { 'use strict'; return ng.module('app', [ 'app.services', 'app.controllers', 'app.filters', 'app.directives' ]); });
: (controllers), (directives), (filters), (services). , .
routes.js
(routes) . ( ).
define(['./app'], function (app) { 'use strict'; return app.config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/view1', { templateUrl: 'partials/partial1.html', controller: 'MyCtrl1' }); $routeProvider.when('/view2', { templateUrl: 'partials/partial2.html', controller: 'MyCtrl2' }); $routeProvider.otherwise({ redirectTo: '/view1' }); }]); });
:
app.controllers
.
controllers/module.js
define(['angular'], function (ng) { 'use strict'; return ng.module('app.controllers', []); });
(. )
controllers/index.js
define, . module.js ( ). . RequireJs .
define([ './my-ctrl-1', './my-ctrl-2' ], function () {});
controllers/my-ctrl-1.js
app.controllers
. :
define(['./module'], function (controllers) { 'use strict'; controllers.controller('MyCtrl1', [function ($scope) {}]); });
, ./module.js
.
:
. AngularJs RequireJs. , .
:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>My AngularJS AngularJS + RequireJS App</title> <link rel="stylesheet" href="css/app.css"> </head> <body> <ul class="menu"> <li><a href="#/view1">view1</a></li> <li><a href="#/view2">view2</a></li> </ul> <div data-ng-view></div> <div>Angular Require seed app: v<span app-version></span></div> <script src="lib/requirejs/require.js" data-main="js/main.js"></script> </body> </html>
. index.html
, .
main.js
RequireJS.
require.config({ // paths: { 'domReady': '../lib/requirejs-domready/domReady', 'angular': '../lib/angular/angular' }, // angular AMD , angular shim: { 'angular': { exports: 'angular' } }, // deps: ['./bootstrap'] });
?
paths
. AngularJs ( shim ). , bootstrap.js
.
bootstrap.js
AngularJs, bootstrap.js
( , ng-app
HTML ). routes.js
, , .
, ,
angular->app->routes
: AngularJs (app) (routes).
/** * bootstraps angular onto the window.document node */ define([ 'require', 'angular', 'app', 'routes' ], function (require, ng) { 'use strict'; require(['domReady!'], function (document) { ng.bootstrap(document, ['app']); }); });
domReady
, , DOM . , app.js
, .
app.js
app.js
.
define([ 'angular', './controllers/index', './directives/index', './filters/index', './services/index' ], function (ng) { 'use strict'; return ng.module('app', [ 'app.services', 'app.controllers', 'app.filters', 'app.directives' ]); });
: (controllers), (directives), (filters), (services). , .
routes.js
(routes) . ( ).
define(['./app'], function (app) { 'use strict'; return app.config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/view1', { templateUrl: 'partials/partial1.html', controller: 'MyCtrl1' }); $routeProvider.when('/view2', { templateUrl: 'partials/partial2.html', controller: 'MyCtrl2' }); $routeProvider.otherwise({ redirectTo: '/view1' }); }]); });
:
app.controllers
.
controllers/module.js
define(['angular'], function (ng) { 'use strict'; return ng.module('app.controllers', []); });
(. )
controllers/index.js
define, . module.js ( ). . RequireJs .
define([ './my-ctrl-1', './my-ctrl-2' ], function () {});
controllers/my-ctrl-1.js
app.controllers
. :
define(['./module'], function (controllers) { 'use strict'; controllers.controller('MyCtrl1', [function ($scope) {}]); });
, ./module.js
.
:
. AngularJs RequireJs. , .
:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>My AngularJS AngularJS + RequireJS App</title> <link rel="stylesheet" href="css/app.css"> </head> <body> <ul class="menu"> <li><a href="#/view1">view1</a></li> <li><a href="#/view2">view2</a></li> </ul> <div data-ng-view></div> <div>Angular Require seed app: v<span app-version></span></div> <script src="lib/requirejs/require.js" data-main="js/main.js"></script> </body> </html>
. index.html
, .
main.js
RequireJS.
require.config({ // paths: { 'domReady': '../lib/requirejs-domready/domReady', 'angular': '../lib/angular/angular' }, // angular AMD , angular shim: { 'angular': { exports: 'angular' } }, // deps: ['./bootstrap'] });
?
paths
. AngularJs ( shim ). , bootstrap.js
.
bootstrap.js
AngularJs, bootstrap.js
( , ng-app
HTML ). routes.js
, , .
, ,
angular->app->routes
: AngularJs (app) (routes).
/** * bootstraps angular onto the window.document node */ define([ 'require', 'angular', 'app', 'routes' ], function (require, ng) { 'use strict'; require(['domReady!'], function (document) { ng.bootstrap(document, ['app']); }); });
domReady
, , DOM . , app.js
, .
app.js
app.js
.
define([ 'angular', './controllers/index', './directives/index', './filters/index', './services/index' ], function (ng) { 'use strict'; return ng.module('app', [ 'app.services', 'app.controllers', 'app.filters', 'app.directives' ]); });
: (controllers), (directives), (filters), (services). , .
routes.js
(routes) . ( ).
define(['./app'], function (app) { 'use strict'; return app.config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/view1', { templateUrl: 'partials/partial1.html', controller: 'MyCtrl1' }); $routeProvider.when('/view2', { templateUrl: 'partials/partial2.html', controller: 'MyCtrl2' }); $routeProvider.otherwise({ redirectTo: '/view1' }); }]); });
:
app.controllers
.
controllers/module.js
define(['angular'], function (ng) { 'use strict'; return ng.module('app.controllers', []); });
(. )
controllers/index.js
define, . module.js ( ). . RequireJs .
define([ './my-ctrl-1', './my-ctrl-2' ], function () {});
controllers/my-ctrl-1.js
app.controllers
. :
define(['./module'], function (controllers) { 'use strict'; controllers.controller('MyCtrl1', [function ($scope) {}]); });
, ./module.js
.
:
. AngularJs RequireJs. , .
:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>My AngularJS AngularJS + RequireJS App</title> <link rel="stylesheet" href="css/app.css"> </head> <body> <ul class="menu"> <li><a href="#/view1">view1</a></li> <li><a href="#/view2">view2</a></li> </ul> <div data-ng-view></div> <div>Angular Require seed app: v<span app-version></span></div> <script src="lib/requirejs/require.js" data-main="js/main.js"></script> </body> </html>
. index.html
, .
main.js
RequireJS.
require.config({ // paths: { 'domReady': '../lib/requirejs-domready/domReady', 'angular': '../lib/angular/angular' }, // angular AMD , angular shim: { 'angular': { exports: 'angular' } }, // deps: ['./bootstrap'] });
?
paths
. AngularJs ( shim ). , bootstrap.js
.
bootstrap.js
AngularJs, bootstrap.js
( , ng-app
HTML ). routes.js
, , .
, ,
angular->app->routes
: AngularJs (app) (routes).
/** * bootstraps angular onto the window.document node */ define([ 'require', 'angular', 'app', 'routes' ], function (require, ng) { 'use strict'; require(['domReady!'], function (document) { ng.bootstrap(document, ['app']); }); });
domReady
, , DOM . , app.js
, .
app.js
app.js
.
define([ 'angular', './controllers/index', './directives/index', './filters/index', './services/index' ], function (ng) { 'use strict'; return ng.module('app', [ 'app.services', 'app.controllers', 'app.filters', 'app.directives' ]); });
: (controllers), (directives), (filters), (services). , .
routes.js
(routes) . ( ).
define(['./app'], function (app) { 'use strict'; return app.config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/view1', { templateUrl: 'partials/partial1.html', controller: 'MyCtrl1' }); $routeProvider.when('/view2', { templateUrl: 'partials/partial2.html', controller: 'MyCtrl2' }); $routeProvider.otherwise({ redirectTo: '/view1' }); }]); });
:
app.controllers
.
controllers/module.js
define(['angular'], function (ng) { 'use strict'; return ng.module('app.controllers', []); });
(. )
controllers/index.js
define, . module.js ( ). . RequireJs .
define([ './my-ctrl-1', './my-ctrl-2' ], function () {});
controllers/my-ctrl-1.js
app.controllers
. :
define(['./module'], function (controllers) { 'use strict'; controllers.controller('MyCtrl1', [function ($scope) {}]); });
, ./module.js
.
:
. AngularJs RequireJs. , .
:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>My AngularJS AngularJS + RequireJS App</title> <link rel="stylesheet" href="css/app.css"> </head> <body> <ul class="menu"> <li><a href="#/view1">view1</a></li> <li><a href="#/view2">view2</a></li> </ul> <div data-ng-view></div> <div>Angular Require seed app: v<span app-version></span></div> <script src="lib/requirejs/require.js" data-main="js/main.js"></script> </body> </html>
. index.html
, .
main.js
RequireJS.
require.config({ // paths: { 'domReady': '../lib/requirejs-domready/domReady', 'angular': '../lib/angular/angular' }, // angular AMD , angular shim: { 'angular': { exports: 'angular' } }, // deps: ['./bootstrap'] });
?
paths
. AngularJs ( shim ). , bootstrap.js
.
bootstrap.js
AngularJs, bootstrap.js
( , ng-app
HTML ). routes.js
, , .
, ,
angular->app->routes
: AngularJs (app) (routes).
/** * bootstraps angular onto the window.document node */ define([ 'require', 'angular', 'app', 'routes' ], function (require, ng) { 'use strict'; require(['domReady!'], function (document) { ng.bootstrap(document, ['app']); }); });
domReady
, , DOM . , app.js
, .
app.js
app.js
.
define([ 'angular', './controllers/index', './directives/index', './filters/index', './services/index' ], function (ng) { 'use strict'; return ng.module('app', [ 'app.services', 'app.controllers', 'app.filters', 'app.directives' ]); });
: (controllers), (directives), (filters), (services). , .
routes.js
(routes) . ( ).
define(['./app'], function (app) { 'use strict'; return app.config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/view1', { templateUrl: 'partials/partial1.html', controller: 'MyCtrl1' }); $routeProvider.when('/view2', { templateUrl: 'partials/partial2.html', controller: 'MyCtrl2' }); $routeProvider.otherwise({ redirectTo: '/view1' }); }]); });
:
app.controllers
.
controllers/module.js
define(['angular'], function (ng) { 'use strict'; return ng.module('app.controllers', []); });
(. )
controllers/index.js
define, . module.js ( ). . RequireJs .
define([ './my-ctrl-1', './my-ctrl-2' ], function () {});
controllers/my-ctrl-1.js
app.controllers
. :
define(['./module'], function (controllers) { 'use strict'; controllers.controller('MyCtrl1', [function ($scope) {}]); });
, ./module.js
.
:
. AngularJs RequireJs. , .
:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>My AngularJS AngularJS + RequireJS App</title> <link rel="stylesheet" href="css/app.css"> </head> <body> <ul class="menu"> <li><a href="#/view1">view1</a></li> <li><a href="#/view2">view2</a></li> </ul> <div data-ng-view></div> <div>Angular Require seed app: v<span app-version></span></div> <script src="lib/requirejs/require.js" data-main="js/main.js"></script> </body> </html>
. index.html
, .
main.js
RequireJS.
require.config({ // paths: { 'domReady': '../lib/requirejs-domready/domReady', 'angular': '../lib/angular/angular' }, // angular AMD , angular shim: { 'angular': { exports: 'angular' } }, // deps: ['./bootstrap'] });
?
paths
. AngularJs ( shim ). , bootstrap.js
.
bootstrap.js
AngularJs, bootstrap.js
( , ng-app
HTML ). routes.js
, , .
, ,
angular->app->routes
: AngularJs (app) (routes).
/** * bootstraps angular onto the window.document node */ define([ 'require', 'angular', 'app', 'routes' ], function (require, ng) { 'use strict'; require(['domReady!'], function (document) { ng.bootstrap(document, ['app']); }); });
domReady
, , DOM . , app.js
, .
app.js
app.js
.
define([ 'angular', './controllers/index', './directives/index', './filters/index', './services/index' ], function (ng) { 'use strict'; return ng.module('app', [ 'app.services', 'app.controllers', 'app.filters', 'app.directives' ]); });
: (controllers), (directives), (filters), (services). , .
routes.js
(routes) . ( ).
define(['./app'], function (app) { 'use strict'; return app.config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/view1', { templateUrl: 'partials/partial1.html', controller: 'MyCtrl1' }); $routeProvider.when('/view2', { templateUrl: 'partials/partial2.html', controller: 'MyCtrl2' }); $routeProvider.otherwise({ redirectTo: '/view1' }); }]); });
:
app.controllers
.
controllers/module.js
define(['angular'], function (ng) { 'use strict'; return ng.module('app.controllers', []); });
(. )
controllers/index.js
define, . module.js ( ). . RequireJs .
define([ './my-ctrl-1', './my-ctrl-2' ], function () {});
controllers/my-ctrl-1.js
app.controllers
. :
define(['./module'], function (controllers) { 'use strict'; controllers.controller('MyCtrl1', [function ($scope) {}]); });
, ./module.js
.
:
. AngularJs RequireJs. , .
:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>My AngularJS AngularJS + RequireJS App</title> <link rel="stylesheet" href="css/app.css"> </head> <body> <ul class="menu"> <li><a href="#/view1">view1</a></li> <li><a href="#/view2">view2</a></li> </ul> <div data-ng-view></div> <div>Angular Require seed app: v<span app-version></span></div> <script src="lib/requirejs/require.js" data-main="js/main.js"></script> </body> </html>
. index.html
, .
main.js
RequireJS.
require.config({ // paths: { 'domReady': '../lib/requirejs-domready/domReady', 'angular': '../lib/angular/angular' }, // angular AMD , angular shim: { 'angular': { exports: 'angular' } }, // deps: ['./bootstrap'] });
?
paths
. AngularJs ( shim ). , bootstrap.js
.
bootstrap.js
AngularJs, bootstrap.js
( , ng-app
HTML ). routes.js
, , .
, ,
angular->app->routes
: AngularJs (app) (routes).
/** * bootstraps angular onto the window.document node */ define([ 'require', 'angular', 'app', 'routes' ], function (require, ng) { 'use strict'; require(['domReady!'], function (document) { ng.bootstrap(document, ['app']); }); });
domReady
, , DOM . , app.js
, .
app.js
app.js
.
define([ 'angular', './controllers/index', './directives/index', './filters/index', './services/index' ], function (ng) { 'use strict'; return ng.module('app', [ 'app.services', 'app.controllers', 'app.filters', 'app.directives' ]); });
: (controllers), (directives), (filters), (services). , .
routes.js
(routes) . ( ).
define(['./app'], function (app) { 'use strict'; return app.config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/view1', { templateUrl: 'partials/partial1.html', controller: 'MyCtrl1' }); $routeProvider.when('/view2', { templateUrl: 'partials/partial2.html', controller: 'MyCtrl2' }); $routeProvider.otherwise({ redirectTo: '/view1' }); }]); });
:
app.controllers
.
controllers/module.js
define(['angular'], function (ng) { 'use strict'; return ng.module('app.controllers', []); });
(. )
controllers/index.js
define, . module.js ( ). . RequireJs .
define([ './my-ctrl-1', './my-ctrl-2' ], function () {});
controllers/my-ctrl-1.js
app.controllers
. :
define(['./module'], function (controllers) { 'use strict'; controllers.controller('MyCtrl1', [function ($scope) {}]); });
, ./module.js
.
:
. AngularJs RequireJs. , .
:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>My AngularJS AngularJS + RequireJS App</title> <link rel="stylesheet" href="css/app.css"> </head> <body> <ul class="menu"> <li><a href="#/view1">view1</a></li> <li><a href="#/view2">view2</a></li> </ul> <div data-ng-view></div> <div>Angular Require seed app: v<span app-version></span></div> <script src="lib/requirejs/require.js" data-main="js/main.js"></script> </body> </html>
. index.html
, .
main.js
RequireJS.
require.config({ // paths: { 'domReady': '../lib/requirejs-domready/domReady', 'angular': '../lib/angular/angular' }, // angular AMD , angular shim: { 'angular': { exports: 'angular' } }, // deps: ['./bootstrap'] });
?
paths
. AngularJs ( shim ). , bootstrap.js
.
bootstrap.js
AngularJs, bootstrap.js
( , ng-app
HTML ). routes.js
, , .
, ,
angular->app->routes
: AngularJs (app) (routes).
/** * bootstraps angular onto the window.document node */ define([ 'require', 'angular', 'app', 'routes' ], function (require, ng) { 'use strict'; require(['domReady!'], function (document) { ng.bootstrap(document, ['app']); }); });
domReady
, , DOM . , app.js
, .
app.js
app.js
.
define([ 'angular', './controllers/index', './directives/index', './filters/index', './services/index' ], function (ng) { 'use strict'; return ng.module('app', [ 'app.services', 'app.controllers', 'app.filters', 'app.directives' ]); });
: (controllers), (directives), (filters), (services). , .
routes.js
(routes) . ( ).
define(['./app'], function (app) { 'use strict'; return app.config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/view1', { templateUrl: 'partials/partial1.html', controller: 'MyCtrl1' }); $routeProvider.when('/view2', { templateUrl: 'partials/partial2.html', controller: 'MyCtrl2' }); $routeProvider.otherwise({ redirectTo: '/view1' }); }]); });
:
app.controllers
.
controllers/module.js
define(['angular'], function (ng) { 'use strict'; return ng.module('app.controllers', []); });
(. )
controllers/index.js
define, . module.js ( ). . RequireJs .
define([ './my-ctrl-1', './my-ctrl-2' ], function () {});
controllers/my-ctrl-1.js
app.controllers
. :
define(['./module'], function (controllers) { 'use strict'; controllers.controller('MyCtrl1', [function ($scope) {}]); });
, ./module.js
.
:
. AngularJs RequireJs. , .
:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>My AngularJS AngularJS + RequireJS App</title> <link rel="stylesheet" href="css/app.css"> </head> <body> <ul class="menu"> <li><a href="#/view1">view1</a></li> <li><a href="#/view2">view2</a></li> </ul> <div data-ng-view></div> <div>Angular Require seed app: v<span app-version></span></div> <script src="lib/requirejs/require.js" data-main="js/main.js"></script> </body> </html>
. index.html
, .
main.js
RequireJS.
require.config({ // paths: { 'domReady': '../lib/requirejs-domready/domReady', 'angular': '../lib/angular/angular' }, // angular AMD , angular shim: { 'angular': { exports: 'angular' } }, // deps: ['./bootstrap'] });
?
paths
. AngularJs ( shim ). , bootstrap.js
.
bootstrap.js
AngularJs, bootstrap.js
( , ng-app
HTML ). routes.js
, , .
, ,
angular->app->routes
: AngularJs (app) (routes).
/** * bootstraps angular onto the window.document node */ define([ 'require', 'angular', 'app', 'routes' ], function (require, ng) { 'use strict'; require(['domReady!'], function (document) { ng.bootstrap(document, ['app']); }); });
domReady
, , DOM . , app.js
, .
app.js
app.js
.
define([ 'angular', './controllers/index', './directives/index', './filters/index', './services/index' ], function (ng) { 'use strict'; return ng.module('app', [ 'app.services', 'app.controllers', 'app.filters', 'app.directives' ]); });
: (controllers), (directives), (filters), (services). , .
routes.js
(routes) . ( ).
define(['./app'], function (app) { 'use strict'; return app.config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/view1', { templateUrl: 'partials/partial1.html', controller: 'MyCtrl1' }); $routeProvider.when('/view2', { templateUrl: 'partials/partial2.html', controller: 'MyCtrl2' }); $routeProvider.otherwise({ redirectTo: '/view1' }); }]); });
:
app.controllers
.
controllers/module.js
define(['angular'], function (ng) { 'use strict'; return ng.module('app.controllers', []); });
(. )
controllers/index.js
define, . module.js ( ). . RequireJs .
define([ './my-ctrl-1', './my-ctrl-2' ], function () {});
controllers/my-ctrl-1.js
app.controllers
. :
define(['./module'], function (controllers) { 'use strict'; controllers.controller('MyCtrl1', [function ($scope) {}]); });
, ./module.js
.
:
. AngularJs RequireJs. , .
:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>My AngularJS AngularJS + RequireJS App</title> <link rel="stylesheet" href="css/app.css"> </head> <body> <ul class="menu"> <li><a href="#/view1">view1</a></li> <li><a href="#/view2">view2</a></li> </ul> <div data-ng-view></div> <div>Angular Require seed app: v<span app-version></span></div> <script src="lib/requirejs/require.js" data-main="js/main.js"></script> </body> </html>
. index.html
, .
main.js
RequireJS.
require.config({ // paths: { 'domReady': '../lib/requirejs-domready/domReady', 'angular': '../lib/angular/angular' }, // angular AMD , angular shim: { 'angular': { exports: 'angular' } }, // deps: ['./bootstrap'] });
?
paths
. AngularJs ( shim ). , bootstrap.js
.
bootstrap.js
AngularJs, bootstrap.js
( , ng-app
HTML ). routes.js
, , .
, ,
angular->app->routes
: AngularJs (app) (routes).
/** * bootstraps angular onto the window.document node */ define([ 'require', 'angular', 'app', 'routes' ], function (require, ng) { 'use strict'; require(['domReady!'], function (document) { ng.bootstrap(document, ['app']); }); });
domReady
, , DOM . , app.js
, .
app.js
app.js
.
define([ 'angular', './controllers/index', './directives/index', './filters/index', './services/index' ], function (ng) { 'use strict'; return ng.module('app', [ 'app.services', 'app.controllers', 'app.filters', 'app.directives' ]); });
: (controllers), (directives), (filters), (services). , .
routes.js
(routes) . ( ).
define(['./app'], function (app) { 'use strict'; return app.config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/view1', { templateUrl: 'partials/partial1.html', controller: 'MyCtrl1' }); $routeProvider.when('/view2', { templateUrl: 'partials/partial2.html', controller: 'MyCtrl2' }); $routeProvider.otherwise({ redirectTo: '/view1' }); }]); });
:
app.controllers
.
controllers/module.js
define(['angular'], function (ng) { 'use strict'; return ng.module('app.controllers', []); });
(. )
controllers/index.js
define, . module.js ( ). . RequireJs .
define([ './my-ctrl-1', './my-ctrl-2' ], function () {});
controllers/my-ctrl-1.js
app.controllers
. :
define(['./module'], function (controllers) { 'use strict'; controllers.controller('MyCtrl1', [function ($scope) {}]); });
, ./module.js
.
:
. AngularJs RequireJs. , .
:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>My AngularJS AngularJS + RequireJS App</title> <link rel="stylesheet" href="css/app.css"> </head> <body> <ul class="menu"> <li><a href="#/view1">view1</a></li> <li><a href="#/view2">view2</a></li> </ul> <div data-ng-view></div> <div>Angular Require seed app: v<span app-version></span></div> <script src="lib/requirejs/require.js" data-main="js/main.js"></script> </body> </html>
. index.html
, .
main.js
RequireJS.
require.config({ // paths: { 'domReady': '../lib/requirejs-domready/domReady', 'angular': '../lib/angular/angular' }, // angular AMD , angular shim: { 'angular': { exports: 'angular' } }, // deps: ['./bootstrap'] });
?
paths
. AngularJs ( shim ). , bootstrap.js
.
bootstrap.js
AngularJs, bootstrap.js
( , ng-app
HTML ). routes.js
, , .
, ,
angular->app->routes
: AngularJs (app) (routes).
/** * bootstraps angular onto the window.document node */ define([ 'require', 'angular', 'app', 'routes' ], function (require, ng) { 'use strict'; require(['domReady!'], function (document) { ng.bootstrap(document, ['app']); }); });
domReady
, , DOM . , app.js
, .
app.js
app.js
.
define([ 'angular', './controllers/index', './directives/index', './filters/index', './services/index' ], function (ng) { 'use strict'; return ng.module('app', [ 'app.services', 'app.controllers', 'app.filters', 'app.directives' ]); });
: (controllers), (directives), (filters), (services). , .
routes.js
(routes) . ( ).
define(['./app'], function (app) { 'use strict'; return app.config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/view1', { templateUrl: 'partials/partial1.html', controller: 'MyCtrl1' }); $routeProvider.when('/view2', { templateUrl: 'partials/partial2.html', controller: 'MyCtrl2' }); $routeProvider.otherwise({ redirectTo: '/view1' }); }]); });
:
app.controllers
.
controllers/module.js
define(['angular'], function (ng) { 'use strict'; return ng.module('app.controllers', []); });
(. )
controllers/index.js
define, . module.js ( ). . RequireJs .
define([ './my-ctrl-1', './my-ctrl-2' ], function () {});
controllers/my-ctrl-1.js
app.controllers
. :
define(['./module'], function (controllers) { 'use strict'; controllers.controller('MyCtrl1', [function ($scope) {}]); });
, ./module.js
.
:
. AngularJs RequireJs. , .
:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>My AngularJS AngularJS + RequireJS App</title> <link rel="stylesheet" href="css/app.css"> </head> <body> <ul class="menu"> <li><a href="#/view1">view1</a></li> <li><a href="#/view2">view2</a></li> </ul> <div data-ng-view></div> <div>Angular Require seed app: v<span app-version></span></div> <script src="lib/requirejs/require.js" data-main="js/main.js"></script> </body> </html>
. index.html
, .
main.js
RequireJS.
require.config({ // paths: { 'domReady': '../lib/requirejs-domready/domReady', 'angular': '../lib/angular/angular' }, // angular AMD , angular shim: { 'angular': { exports: 'angular' } }, // deps: ['./bootstrap'] });
?
paths
. AngularJs ( shim ). , bootstrap.js
.
bootstrap.js
AngularJs, bootstrap.js
( , ng-app
HTML ). routes.js
, , .
, ,
angular->app->routes
: AngularJs (app) (routes).
/** * bootstraps angular onto the window.document node */ define([ 'require', 'angular', 'app', 'routes' ], function (require, ng) { 'use strict'; require(['domReady!'], function (document) { ng.bootstrap(document, ['app']); }); });
domReady
, , DOM . , app.js
, .
app.js
app.js
.
define([ 'angular', './controllers/index', './directives/index', './filters/index', './services/index' ], function (ng) { 'use strict'; return ng.module('app', [ 'app.services', 'app.controllers', 'app.filters', 'app.directives' ]); });
: (controllers), (directives), (filters), (services). , .
routes.js
(routes) . ( ).
define(['./app'], function (app) { 'use strict'; return app.config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/view1', { templateUrl: 'partials/partial1.html', controller: 'MyCtrl1' }); $routeProvider.when('/view2', { templateUrl: 'partials/partial2.html', controller: 'MyCtrl2' }); $routeProvider.otherwise({ redirectTo: '/view1' }); }]); });
:
app.controllers
.
controllers/module.js
define(['angular'], function (ng) { 'use strict'; return ng.module('app.controllers', []); });
(. )
controllers/index.js
define, . module.js ( ). . RequireJs .
define([ './my-ctrl-1', './my-ctrl-2' ], function () {});
controllers/my-ctrl-1.js
app.controllers
. :
define(['./module'], function (controllers) { 'use strict'; controllers.controller('MyCtrl1', [function ($scope) {}]); });
, ./module.js
.
:
. AngularJs RequireJs. , .
:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>My AngularJS AngularJS + RequireJS App</title> <link rel="stylesheet" href="css/app.css"> </head> <body> <ul class="menu"> <li><a href="#/view1">view1</a></li> <li><a href="#/view2">view2</a></li> </ul> <div data-ng-view></div> <div>Angular Require seed app: v<span app-version></span></div> <script src="lib/requirejs/require.js" data-main="js/main.js"></script> </body> </html>
. index.html
, .
main.js
RequireJS.
require.config({ // paths: { 'domReady': '../lib/requirejs-domready/domReady', 'angular': '../lib/angular/angular' }, // angular AMD , angular shim: { 'angular': { exports: 'angular' } }, // deps: ['./bootstrap'] });
?
paths
. AngularJs ( shim ). , bootstrap.js
.
bootstrap.js
AngularJs, bootstrap.js
( , ng-app
HTML ). routes.js
, , .
, ,
angular->app->routes
: AngularJs (app) (routes).
/** * bootstraps angular onto the window.document node */ define([ 'require', 'angular', 'app', 'routes' ], function (require, ng) { 'use strict'; require(['domReady!'], function (document) { ng.bootstrap(document, ['app']); }); });
domReady
, , DOM . , app.js
, .
app.js
app.js
.
define([ 'angular', './controllers/index', './directives/index', './filters/index', './services/index' ], function (ng) { 'use strict'; return ng.module('app', [ 'app.services', 'app.controllers', 'app.filters', 'app.directives' ]); });
: (controllers), (directives), (filters), (services). , .
routes.js
(routes) . ( ).
define(['./app'], function (app) { 'use strict'; return app.config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/view1', { templateUrl: 'partials/partial1.html', controller: 'MyCtrl1' }); $routeProvider.when('/view2', { templateUrl: 'partials/partial2.html', controller: 'MyCtrl2' }); $routeProvider.otherwise({ redirectTo: '/view1' }); }]); });
:
app.controllers
.
controllers/module.js
define(['angular'], function (ng) { 'use strict'; return ng.module('app.controllers', []); });
(. )
controllers/index.js
define, . module.js ( ). . RequireJs .
define([ './my-ctrl-1', './my-ctrl-2' ], function () {});
controllers/my-ctrl-1.js
app.controllers
. :
define(['./module'], function (controllers) { 'use strict'; controllers.controller('MyCtrl1', [function ($scope) {}]); });
, ./module.js
.
:
. AngularJs RequireJs. , .
Source: https://habr.com/ru/post/225931/
All Articles