4

I'm trying to use ng-table in my anuglarjs application. I didn't realize that npm version is f up and new release is not there yet, however my app is in an advenced stage and I can not use bower vesion.

I was trying to load latest version from git npm install git+ssh://git@github.com/esvit/ng-table.git --save

and then load it in my entry file:

import angular from 'angular';
import ngTable from 'ng-table';

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

Sadly webpack throw a lot of errors:

ERROR in ./src/app.js
Module not found: Error: Cannot resolve module 'angular'(...)

I was also trying to use imports-loader:

const ngTable = require('imports?define=>false,angular!ng-table');

but no success either. Could somebody points me in right direction? I really would like to not rewrite all chore stuff because of the one lib.

Eggy
  • 4,052
  • 7
  • 23
  • 39

2 Answers2

3

you can use ng-table like this:

// app.js
import angular from 'angular';
import ngTable from 'ng-table/dist/ng-table';

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

since looks like doesn't have and index config for commonjs modules

check this comment https://github.com/esvit/ng-table/issues/764#issuecomment-184357333

Diego Toro
  • 33
  • 5
1

I was trying to find the solution as well. Here it is. "import" quiet does not work for me. Gives out an error

webpack.config.js

config.resolve = {
  extensions: ['', '.js'],
  alias: {
    'ng-table': 'ng-table/dist/ng-table'
  },
  modulesDirectories: [ 'node_modules', 'bower_components' ],
};

config.module = {
  loaders: [{
    test: require.resolve('ng-table'),
    loader: 'imports-loader?define=>false,$=jquery,angular'
   }]
}

app.js

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

define=>false was the one of key things which I was missing when following the github answer. and injecting angular into ng-table is being done in the loader line.

Sairam
  • 2,708
  • 1
  • 25
  • 34