1

Angular1 を es6 に変換し、webpack の使用を開始しています。そのため、すべてのファイルで「インポート/エクスポート モジュール」を使用する必要があります。

持っているすべてのファイル js にモジュールをインポートする必要がありますか? たとえば、角度の $window でさえ?ルーターの解決でも?

変換に苦労しています。

大きなアプリでそれを行う簡単な方法はありますか?

ありがとう!

4

1 に答える 1

0

angular をインポートすると、$window、$timeout、$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);
于 2017-01-04T19:56:03.360 に答える