Answer the question
In order to leave comments, you need to log in
How to properly split an Angular application by files?
Good evening!
How will it be more competent to split an Angular 1.x application into files and directories, so that webpack or browserify can then glue them together?
Option 1 - import function (array):
/**
* app.js
*/
const MainCtrl = require("./controllers/mainCtrl.js")
const App = angular.module('App', []);
App.controller('MainCtrl', MainCtrl);
/**
* mainCtrl.js
*/
module.exports = [
'$scope',
($scope) => {
// code ...
}
]
/**
* app.js
*/
const App = angular.module('App', []);
require("./controllers/mainCtrl.js")(App);
/**
* mainCtrl.js
*/
module.exports = function (App) {
App.controller('MainCtrl', [
'$scope',
($scope) => {
// code ...
}
]);
};
/**
* app.js
*/
const App = angular.module('App', []);
require("./controllers/mainCtrl.js")('App');
/**
* mainCtrl.js
*/
module.exports = function (moduleName) {
const App = angular.module(moduleName);
App.controller('MainCtrl', [
'$scope',
($scope) => {
// code ...
}
]);
};
Answer the question
In order to leave comments, you need to log in
angular-tips.com/blog/2015/06/using-angular-1-dot-...
https://github.com/johnpapa/angular-styleguide
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question