Questions tagged [angular-module]

You can think of an Angular/AngularJS module as a container for the different parts of your app – controllers, services, filters, directives, etc.

Most applications have a main method that instantiates and wires together the different parts of the application.

Angular apps don't have a main method. Instead modules declaratively specify how an application should be bootstrapped. There are several advantages to this approach:

  • The declarative process is easier to understand.
  • You can package code as reusable modules.
  • The modules can be loaded in any order (or even in parallel) because modules delay execution.
  • Unit tests only have load relevant modules, which keeps them fast.
  • End-to-end tests can use modules to override configuration.

Full documentation on AngularJS modules.

471 questions
438
votes
6 answers

What is the difference between declarations, providers, and import in NgModule?

I am trying to understand Angular (sometimes called Angular2+), then I came across @Module: Imports Declarations Providers Following Angular Quick Start
Ramesh Papaganti
  • 5,733
  • 3
  • 22
  • 33
241
votes
7 answers

Use component from another module

I have Angular 2.0.0 app generated with angular-cli. When I create a component and add it to AppModule's declarations array it's all good, it works. I decided to separate the components, so I created a TaskModule and a component TaskCard. Now I…
Evgeni Dimitrov
  • 19,437
  • 29
  • 105
  • 137
167
votes
16 answers

Angular 2 'component' is not a known element

I'm trying to use a component I created inside the AppModule in other modules. I get the following error though: "Uncaught (in promise): Error: Template parse errors: 'contacts-box' is not a known element: If 'contacts-box' is an Angular…
Aranha
  • 2,153
  • 3
  • 11
  • 26
151
votes
6 answers

What is entryComponents in angular ngModule?

I am working on an Ionic app ( 2.0.0-rc0 ) which depends on angular 2 . So the new introduction of ngModules is included. I am adding my app.module.ts. below. import { NgModule } from '@angular/core'; import { IonicApp, IonicModule } from…
raj
  • 5,493
  • 5
  • 26
  • 49
87
votes
5 answers

How to declare a pipe globally to use in different modules?

I have a custom pipe named CurrConvertPipe import {Pipe, PipeTransform} from '@angular/core'; import {LocalStorageService} from './local-storage'; @Pipe({name: 'currConvert', pure: false}) export class CurrConvertPipe implements PipeTransform { …
Sajeetharan
  • 186,121
  • 54
  • 283
  • 331
58
votes
2 answers

Role of imports / exports in Angular 2+ ngModule

I'm learning Angular 2+ and I'm having a hard time understanding the role of imports/exports in an ngModule. More specifically why is important to import a module if you're going to import it anyway using es6 syntax as well import { BrowserModule }…
Doua Beri
  • 9,236
  • 15
  • 78
  • 126
54
votes
3 answers

No Provider for CustomPipe - angular 4

I've a custom decimal format pipe that uses angular Decimal pipe inturn. This pipe is a part of the shared module. I'm use this in feature module and getting no provider error when running the application. Please ignore if there are any…
mperle
  • 2,514
  • 7
  • 12
  • 31
19
votes
4 answers

Angular router: how to pass data to lazy loading module?

I have the following routing paths for a module of my Angular app: @NgModule({ imports: [ RouterModule.forChild([ { path: 'documents', data: { myObject: MyConstants.OPTION_ONE }, …
smartmouse
  • 11,808
  • 26
  • 77
  • 154
18
votes
2 answers

Angular - Using a component across multiple modules

What I'm using Angular What I'm trying to do I have a loading component I want to reuse across multiple modules What I've done I've created a new module called 'loading-overlay' Inside this module I export the overlay component I add this…
MegaTron
  • 2,395
  • 4
  • 25
  • 40
15
votes
1 answer

Getting 'ngbCollapse' since it isn't a known property of 'div'. error after moving components into sub module

Error compiler.js:215 Uncaught Error: Template parse errors: Can't bind to 'ngbCollapse' since it isn't a known property of 'div'. ("][ngbCollapse]="isHidden"> I have a NavbarComponent and a FooterComponent that I want to move into the…
Leon Gaban
  • 27,845
  • 80
  • 281
  • 473
15
votes
2 answers

Angular Service singleton constructor called multiple times

I am trying to use an app-wide service (UserService) that stores authenticated user details. I have set up some routes but found that UserService is instantiated per route. I want them to share the same UserService. I have created a CoreModule…
14
votes
1 answer

How does one go about creating an Angular library wrapper for an existing Javascript library?

Suppose there exists a Javascript library written in plain Javascript and commonly used on vanilla, non-frameworked websites. How does one go about creating an Angular library that can easily be npm installed that would make the library seamless to…
CodyBugstein
  • 17,496
  • 50
  • 159
  • 312
14
votes
1 answer

Angular: Creating plugins for 3rd party packages (libraries)

I created Angular Library (ngx-wig) and I would like to provide an ability to extend its functionality by using plugins. What would be the best place to declare plugin in Angular? (may be something like myLibModule.forRoot(..)) and what type of…
Stepan Suvorov
  • 21,636
  • 25
  • 93
  • 166
14
votes
4 answers

How to create a directive to be used in any module?

How can I create a directive without linking it to a specific module which can be used in any module, such as the build-in directives.
Ghyath Serhal
  • 7,106
  • 6
  • 41
  • 57
13
votes
1 answer

Angular 6 providedIn - how to customize the @Injectable() provider for dependency injection?

In Angular 5, if I had AbstractClassService and ExtendedClassService that extends the abstract, I could do this in my NgModule's providers array: @NgModule({ providers: [ {provide: AbstractClassService, useClass: ExtendedClassService} …
BeetleJuice
  • 33,709
  • 16
  • 78
  • 137
1
2 3
31 32