2

Till now I practiced my ANgular 2 projects from angular-seed from here

While doing with this project ,I use to include all third-party libraries in system.config.js like this

 map: {
   'ng2-file-upload': 'npm:ng2-file-upload'
 },
 packages: {
  ng2-file-upload: {
    defaultExtension: 'js'
  }

This worked very fine for me.Now I am using angular cli and I am confused of including in it.

In angular-cli.json,

 "scripts": [
     ?????
  ],

Can any one please help me.Thanks

MMR
  • 2,869
  • 13
  • 56
  • 110
  • AFAIR you can import your scripts directly into your components and need not include then in your `angualr-cli.json` Eg: `import {DropdownModule} from 'primeng/components/dropdown/dropdown';` – yashhy Apr 20 '17 at 07:01

2 Answers2

1

You store your dependencies in node_modules folder. When you need them, you import them inside a file using import statement. When compiled into JS, import are usually replaced with require.

When you code is being executed in a browser, you need a loader to load those files from node_modules and such loader is SystemJS. Learn more why SystemJS is needed here. SystemJS needs to know the path to modules, that's why you need to add dependencies to system.config.js.

However, angular-cli uses webpack module bundler, which has its own built-in loader. When webpack bundles files, it resolves paths and inlines them into resulting bundle. That's why you don't need to add paths anywhere when using angular-cli.

I just tried to use ng2-tag-input with angular-cli. Everything worked OK. I just imported the following into main module:

...
import {TagInputModule} from 'ng2-tag-input';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    ...
    TagInputModule, BrowserAnimationsModule
  ],

And installed @angular/animations. And the following snippet worked OK:

@Component({
  template: '<tag-input [(ngModel)]='items'></tag-input>',
  ...
})
export class AppComponent {
  items = ['Pizza', 'Pasta', 'Parmesan'];
}

You also need to install @angular/animations

Community
  • 1
  • 1
Max Koretskyi
  • 101,079
  • 60
  • 333
  • 488
0

I haven't worked with SystemJS but:

Yes, you can add your libraries to the scripts

"scripts": [
    "pathToLibray"
]

But if you have a npm package, which is built for Angular you can use it without importing it. It gets loaded automatically from your node_modules

Hope I could help :)

Raphael Jenni
  • 318
  • 1
  • 8