有没有办法以模块化方式构造/编写 AngularJS,根据 SystemJS 中的页面路由动态加载/需要? controllers/views
编辑: 这是我目前拥有的,作为使用 SystemJS 的试用版
app.js - 这是在index.html中导入的主文件
// vendor
import angular from 'angular';
//Controllers
import controllers from './controllers/_index.js'
// Routes
import routes from './routes/routes.config.js';
var seedApp = angular.module('seedApp', ['seedApp.route', 'seedApp.controllers']);
angular.element(document).ready(function() {
return angular.bootstrap(document.body, [seedApp.name], {
strictDi: true
});
});
export default seedApp;
_index.js - 所有控制器的索引
import { navCtrl } from './nav.js';
import { aboutCtrl } from './about.js';
var app = angular.module('seedApp.controllers', []);
app.controller('navCtrl', navCtrl);
app.controller('aboutCtrl', aboutCtrl);
路由.config.js
import 'angular-ui-router';
var app = angular.module('seedApp.route', ['ui.router']);
app.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/');
$stateProvider
.state('home', {
url: '/',
templateUrl: 'app/views/home.html'
})
.state('about', {
url: '/about',
templateUrl: 'app/views/about.html',
controller: 'aboutCtrl as about'
});
}]);
export default app;