2017-01-04 54 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);