angular / angular2-seed

MIT License
1.01k stars 640 forks source link

Import node module #169

Closed pascal08 closed 7 years ago

pascal08 commented 7 years ago

Problem:

I'm trying to load angular-ui-tree into a custom component.

package.json

{
  ...
  "dependencies": {
    ...
    "@types/angular-ui-tree": "^2.8.30",
    "angular-ui-tree": "^2.22.5",
    ...
  },
  ...
}

What I have tried:

custom.module.ts

const uiTree = require('angular-ui-tree');

Result: angular-ui-tree is loaded, but throws the following error:

Uncaught ReferenceError: angular is not defined

custom.module.ts

import * as uiTree from 'angular-ui-tree';

tsconfig.json

{
  "compilerOptions": {
     ...
    "typeRoots": [
      "node_modules/@types"
    ],
    "types": ["angular-ui-tree"]
  }
  ...
}

Result: throws error:

File '.../node_modules/@types/angular-ui-tree/index.d.ts' is not a module.

Bottom line

I would like to know how to import a npm package.

Thanks in advance.

pascal08 commented 7 years ago

I realised this question is not relevant since angular-ui-tree is an Angular 1 package. Therefore I'm closing it. Instead I used this package: angular-tree-component