Questions tagged [angular2-modules]
132 questions
16
votes
2 answers
Inherit imports from parent module to child module in Angular2
I made an Angular2 app like described here. It has two components (A,B) which are imported by the global app.module. My idea was, to include shared modules in app.module, so I don't need to mess up every module with redundant code. I want to do that…

Lion
- 16,606
- 23
- 86
- 148
16
votes
2 answers
Angular 2 define data models for multiple modules
I'm currently starting a new project with Angular 2.0 (release Version) and I want to define some global data models/schemas. As I understand it, Angular 2 has no default way of handling pure data classes like this:
export class TestModel {
id:…

A. Ziegler
- 509
- 1
- 6
- 17
12
votes
3 answers
Does import of unnecessary modules in AppModule slow down the Angular 2 app?
In angular(2/4/6) application if we import unnecessary modules in app module will that slow down the application.
Does it impact on the performance of the application ?
@NgModule({
imports: [
BrowserModule.withServerTransition({ appId: 'myId'…

Kooldandy
- 545
- 4
- 15
12
votes
3 answers
Share an external module between lazy loaded modules in angular2
My app has components that use a heavy-weight external package (ag-grid, about 1MB) that is provided as an angular2 module (AgGridModule). I would like to load this package only when the components using it are required, so my ContentModule and all…

Anton Poznyakovskiy
- 2,109
- 1
- 20
- 38
11
votes
3 answers
How do I provide a service in a lazy-loaded module and have that service scoped to just the lazy-loaded module and its components?
In the angular docs FAQ section it states, "Unlike providers of the modules loaded at launch, providers of lazy-loaded modules are module-scoped." link
Does 'module-scoped' here mean just the module or does it extend to include all components…

FlashBanistan
- 426
- 1
- 9
- 25
11
votes
1 answer
Angular2 Lazy Loading Service being Instantiated Twice
I just switched my application over to be lazy-loaded today.
I have a SharedModule that exports a bunch of services.
In my AppModule, I import SharedModule because AppComponent needs access to a few of the shared services.
In another module…

Alex Kibler
- 4,674
- 9
- 44
- 74
10
votes
1 answer
Angular2 - Directive not working when not declared in the same module
I have a directive and I want to use it in multiple modules. Declaring it on each modules produces an error. Thus, I tried to declare it in a shared module and import this shared module to other modules. However, it didn't work. It only works when…

Bünyamin Sarıgül
- 3,031
- 4
- 30
- 55
10
votes
1 answer
Angular 2 - Exporting Auth Services from AuthModule to AppModule
I decided to put LoginComponent, AuthService, LoggedInGuard inside a module called AuthModule:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { AuthComponent } from './auth.component';
import {…

Pasp Ruby
- 957
- 1
- 9
- 22
9
votes
2 answers
Is nested modules bad in Angular?
There is something I wonder about modules. I started Angular 2 a while ago, so i search too many topics but I couldn't find any satisfying answer yet.
When we creating angular 2 application, using modules for sure. Also use nested modules of course.…

orhun.begendi
- 937
- 3
- 16
- 31
8
votes
3 answers
Error: 'app-header' is not a known element: Angular 2
Below is my folder structure.
app
- common
- header
header.component.css
header.component.html
header.component.ts
- footer
footer.component.css
footer.component.html
…

Green Computers
- 723
- 4
- 14
- 24
7
votes
2 answers
Would the module loaded twice in Lazy-load module
When I recently read the Angular2's doc, it says like this:
What if I import the same module twice?
That's not a problem. When three modules all import Module 'A', Angular
evaluates Module 'A' once, the first time it encounters it, and doesn't do…

IcyBrk
- 1,090
- 12
- 21
7
votes
1 answer
Angular 2: Load different versions of the libraries based on the data
I have a requirement where I need to load different version modules based on the data.
Something like monthly data, if some change happens in my module code for the current month, there shouldn't be any change in the view/logic from the previous…

harishkumar329
- 1,210
- 4
- 16
- 34
7
votes
1 answer
Angular 2 - (SystemJS) Unexpected directive 'ViewerComponent' imported by the module 'GalleryModule'
I am getting the following error, not sure what to do:
(SystemJS) Unexpected directive ViewerComponent imported by the module GalleryModule
Thanks for any help relating to what might be causing the error.
In the main app it is importing the…

Pete
- 2,325
- 3
- 16
- 22
7
votes
3 answers
Angular 2.0 Unexpected value '[object Object]' imported by the module 'AppModule'
When I try load my angular 2.0 application I get the following error:
(index):21 Error: Error: Unexpected value '[object Object]' imported by the module 'AppModule'
import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule…

Guy Gallant
- 183
- 1
- 3
- 11
6
votes
1 answer
What is Angular's Custom Module lifecycle?
Is there information about a Module's lifecycle. Currently the lifecycle of Components inside Angular is well documented and we have hook methods like ngOnInit(), ngDoCheck(), etc.
Do we have similar lifecycle hooks for Angular Modules? Where can I…

Hivaga
- 3,738
- 4
- 23
- 36