2017-01-04 57 views
1

我将Angular1转换为es6并开始使用webpack。 因此,我需要在所有文件中使用“导入/导出模块”。es5到es6 + webpack on angular1应用程序

我是否需要在每个js文件上导入模块?例如甚至是角度的$窗口?即使在路由器的决心?

我很努力的转换。

有没有一种简单的方法来做一个大的应用程序?

谢谢!

+0

简而言之:没有什么需要改变的。你能给我们一个例子,你正在努力吗?看看[Todd Motto的Styleguide](https://github.com/toddmotto/angular-styleguide)。 – zeroflagL

回答

0

似水般$窗口,$超时,当您导入角 对于其他任何第三方模块将需要导入的文件,而且它注入到应用程序模块

例子$ HTTP进口:

app.js

import angular from 'angular'; 
import 'angular-ui-router'; // A third-party npm module 
import './controllers/users'; // Custom controller 
import config from './config'; // Custom function 
import run from './app.run'; // Custom function 
const app = angular.module('MyApp', [ 
    'ui.router', 
    'MyApp.controllers.users' 
]); 
app.config(config); 
app.run(run); 

控制器/ user.js的

import angular from 'angular'; 
import '../services/user'; 
import './modals/users'; 

const module = angular.module('MyApp.controllers.users', [ 
    'MyApp.services.user', 
    'MyApp.services.globals', 
    'MyApp.modals.user', 
]); 

const UsersController = ($scope, UserService) => { 
    'ngInject'; 
    $scope.title = 'Users'; 

    $scope.users = UserService.GetAll(); 
} 
module.exports = module.controller('UsersController', UsersController);