2

I have a NPM package that I need to load most of the modules for. I can do the import statement like this:

import * as primeng from 'primeng/primeng';

But in my @NgModule Angular declaration, I need to explicitly list out every single element in the imports section:

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [

    BrowserModule, FormsModule, HttpModule,

    // primeNG
    primeng.ButtonModule, primeng.ChipsModule, primeng.ContextMenuModule, primeng.DataTableModule,
    primeng.DialogModule, primeng.DropdownModule, primeng.EditorModule, primeng.FieldsetModule,
    primeng.GMapModule, primeng.GrowlModule, primeng.InputSwitchModule, primeng.InputTextModule, 
    primeng.PanelMenuModule, primeng.PanelModule, primeng.SharedModule, primeng.SpinnerModule, primeng.TreeModule

  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {}

Is there any way to instead use something like primeng.keys() (which doesn't work) to my imports section of the NgModule?

Bob_Gneu
  • 1,591
  • 1
  • 18
  • 30
John Fisher
  • 137
  • 3
  • 15
  • 4
    Given that it's a decorator, `Object.values(primeng)` should work, no? – Bergi Feb 28 '17 at 19:39
  • ``Object.values(primeng)`` gives me back the typescript error ``Property 'values' does not exist on type 'ArrayConstructor'`` – John Fisher Feb 28 '17 at 23:34
  • @Bergi's comment should be marked as the answer - it worked for me! I needed to convert `import * as Foo from './foo'` into an array of each exported const from './foo'. `Object.values(Foo)` did the trick. – Kevin Wang May 03 '20 at 16:42
  • Object.values didn't work for angular 9. – kaya Jun 07 '20 at 17:43

0 Answers0