将 ngResource 与 webpack 一起使用

using ngResource with webpack

大家早上好,

我最近开始在一个新的 angular 项目中使用 webpack。我真的很喜欢它,非常容易使用。我现在只有一个问题。 我正在尝试导入 ngResource 以在我的模块之一上使用,但我尝试的方式无效。我正在使用 webpack 和 babel loader (es6)

我尝试了以下每一种方式:

//1
import ngResource from 'ng-resource'
angular.module('app', [ngResource])

//2
import 'ng-resource'
angular.module('app', ['ngResource'])


//3
import ngResource from 'ng-resource'
angular.module('app', [ngResource.name])

我什至尝试添加以下加载程序:

{
     test: /[\/]angular-resource\.js$/,
     loader: 'exports?angular.module(\'ngResource\')'
}

然后在我的模块上:

angular.module('app', ['ngResource'])

我做错了什么?我想不通:(

提前致谢, 柴姆

您应该按以下方式导入它:

import ngResource from 'angular-resource';

然后:

angular
  .module('app', [
    ngResource,
    ...
  ]);

导入任何其他 angular 核心模块的相同规则

我也在苦苦思索,原来你需要

npm install angular-resource 而不是 npm install ng-resource

然后做:

import ngResource from 'angular-resource'

或您尝试过的其他方法之一,它们都有效..

这是正确的方法:

var ngResource = require('ng-resource');
ngResource = ngResource(window, angular);

var yourmodule = angular.module( 'yourmodule', [ 'ngResource' ] )...