Shared component not working when imported into lazy loading module
I am trying to load one shared component inside my lazy loaded module.
module. My lazy module imports the SharedModule
like that:
// LazyModule
@NgModule({
imports: [
CommonModule,
SharedModule,
RouterModule.forChild(routes)
],
declarations: [
LazyParentComponent
]
})
Inside my SharedModule, I am importing the Angular material components that I need for the MenuComponent which I export as a shared component:
//SharedModule
@NgModule({
imports: [CommonModule],
declarations: [MenuComponent],
exports: [
MatButtonModule,
MatSelectModule,
MatInputModule,
MatOptionModule,
MatToolbarModule,
MenuComponent
]
})
Then in my LazyParentComponent I am using <app-menu></app-menu>
which should render the MenuComponent, which I include in the sharedModule
.
But if I start this, I always get a lot of errors like Can't bind to 'value' since it isn't a known property of 'mat-select'.
or 'mat-toolbar' is not a known element.
It does however work, if I don't use <app-menu></app-menu>
but instead use the MatButtons from the MatButtonModule
directly.
angular lazy-loading angular-module
add a comment |
I am trying to load one shared component inside my lazy loaded module.
module. My lazy module imports the SharedModule
like that:
// LazyModule
@NgModule({
imports: [
CommonModule,
SharedModule,
RouterModule.forChild(routes)
],
declarations: [
LazyParentComponent
]
})
Inside my SharedModule, I am importing the Angular material components that I need for the MenuComponent which I export as a shared component:
//SharedModule
@NgModule({
imports: [CommonModule],
declarations: [MenuComponent],
exports: [
MatButtonModule,
MatSelectModule,
MatInputModule,
MatOptionModule,
MatToolbarModule,
MenuComponent
]
})
Then in my LazyParentComponent I am using <app-menu></app-menu>
which should render the MenuComponent, which I include in the sharedModule
.
But if I start this, I always get a lot of errors like Can't bind to 'value' since it isn't a known property of 'mat-select'.
or 'mat-toolbar' is not a known element.
It does however work, if I don't use <app-menu></app-menu>
but instead use the MatButtons from the MatButtonModule
directly.
angular lazy-loading angular-module
inside the shared module do you add the components to both declarations and exports?
– omer
Nov 14 '18 at 21:17
I didn't include them in the descriptions but I just saw, that some of the errors go away if I include them in the imports (It's also done like that in the app.module.ts)
– Fabio ha
Nov 14 '18 at 21:23
it doesn't sound right imports are for modules..
– omer
Nov 14 '18 at 21:25
Oh right yes, I see. The MenuComponent is in declarations and export. I was talking about the Angular Material modules
– Fabio ha
Nov 14 '18 at 21:27
add a comment |
I am trying to load one shared component inside my lazy loaded module.
module. My lazy module imports the SharedModule
like that:
// LazyModule
@NgModule({
imports: [
CommonModule,
SharedModule,
RouterModule.forChild(routes)
],
declarations: [
LazyParentComponent
]
})
Inside my SharedModule, I am importing the Angular material components that I need for the MenuComponent which I export as a shared component:
//SharedModule
@NgModule({
imports: [CommonModule],
declarations: [MenuComponent],
exports: [
MatButtonModule,
MatSelectModule,
MatInputModule,
MatOptionModule,
MatToolbarModule,
MenuComponent
]
})
Then in my LazyParentComponent I am using <app-menu></app-menu>
which should render the MenuComponent, which I include in the sharedModule
.
But if I start this, I always get a lot of errors like Can't bind to 'value' since it isn't a known property of 'mat-select'.
or 'mat-toolbar' is not a known element.
It does however work, if I don't use <app-menu></app-menu>
but instead use the MatButtons from the MatButtonModule
directly.
angular lazy-loading angular-module
I am trying to load one shared component inside my lazy loaded module.
module. My lazy module imports the SharedModule
like that:
// LazyModule
@NgModule({
imports: [
CommonModule,
SharedModule,
RouterModule.forChild(routes)
],
declarations: [
LazyParentComponent
]
})
Inside my SharedModule, I am importing the Angular material components that I need for the MenuComponent which I export as a shared component:
//SharedModule
@NgModule({
imports: [CommonModule],
declarations: [MenuComponent],
exports: [
MatButtonModule,
MatSelectModule,
MatInputModule,
MatOptionModule,
MatToolbarModule,
MenuComponent
]
})
Then in my LazyParentComponent I am using <app-menu></app-menu>
which should render the MenuComponent, which I include in the sharedModule
.
But if I start this, I always get a lot of errors like Can't bind to 'value' since it isn't a known property of 'mat-select'.
or 'mat-toolbar' is not a known element.
It does however work, if I don't use <app-menu></app-menu>
but instead use the MatButtons from the MatButtonModule
directly.
angular lazy-loading angular-module
angular lazy-loading angular-module
asked Nov 14 '18 at 21:03
Fabio haFabio ha
178215
178215
inside the shared module do you add the components to both declarations and exports?
– omer
Nov 14 '18 at 21:17
I didn't include them in the descriptions but I just saw, that some of the errors go away if I include them in the imports (It's also done like that in the app.module.ts)
– Fabio ha
Nov 14 '18 at 21:23
it doesn't sound right imports are for modules..
– omer
Nov 14 '18 at 21:25
Oh right yes, I see. The MenuComponent is in declarations and export. I was talking about the Angular Material modules
– Fabio ha
Nov 14 '18 at 21:27
add a comment |
inside the shared module do you add the components to both declarations and exports?
– omer
Nov 14 '18 at 21:17
I didn't include them in the descriptions but I just saw, that some of the errors go away if I include them in the imports (It's also done like that in the app.module.ts)
– Fabio ha
Nov 14 '18 at 21:23
it doesn't sound right imports are for modules..
– omer
Nov 14 '18 at 21:25
Oh right yes, I see. The MenuComponent is in declarations and export. I was talking about the Angular Material modules
– Fabio ha
Nov 14 '18 at 21:27
inside the shared module do you add the components to both declarations and exports?
– omer
Nov 14 '18 at 21:17
inside the shared module do you add the components to both declarations and exports?
– omer
Nov 14 '18 at 21:17
I didn't include them in the descriptions but I just saw, that some of the errors go away if I include them in the imports (It's also done like that in the app.module.ts)
– Fabio ha
Nov 14 '18 at 21:23
I didn't include them in the descriptions but I just saw, that some of the errors go away if I include them in the imports (It's also done like that in the app.module.ts)
– Fabio ha
Nov 14 '18 at 21:23
it doesn't sound right imports are for modules..
– omer
Nov 14 '18 at 21:25
it doesn't sound right imports are for modules..
– omer
Nov 14 '18 at 21:25
Oh right yes, I see. The MenuComponent is in declarations and export. I was talking about the Angular Material modules
– Fabio ha
Nov 14 '18 at 21:27
Oh right yes, I see. The MenuComponent is in declarations and export. I was talking about the Angular Material modules
– Fabio ha
Nov 14 '18 at 21:27
add a comment |
1 Answer
1
active
oldest
votes
You need to include all material modules in imports as well:
Shared Module
@NgModule({
imports: [CommonModule,
MatButtonModule,
MatSelectModule,
MatInputModule,
MatOptionModule,
MatToolbarModule
],
declarations: [MenuComponent],
exports: [
MatButtonModule,
MatSelectModule,
MatInputModule,
MatOptionModule,
MatToolbarModule,
MenuComponent
]
})
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308677%2fshared-component-not-working-when-imported-into-lazy-loading-module%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to include all material modules in imports as well:
Shared Module
@NgModule({
imports: [CommonModule,
MatButtonModule,
MatSelectModule,
MatInputModule,
MatOptionModule,
MatToolbarModule
],
declarations: [MenuComponent],
exports: [
MatButtonModule,
MatSelectModule,
MatInputModule,
MatOptionModule,
MatToolbarModule,
MenuComponent
]
})
add a comment |
You need to include all material modules in imports as well:
Shared Module
@NgModule({
imports: [CommonModule,
MatButtonModule,
MatSelectModule,
MatInputModule,
MatOptionModule,
MatToolbarModule
],
declarations: [MenuComponent],
exports: [
MatButtonModule,
MatSelectModule,
MatInputModule,
MatOptionModule,
MatToolbarModule,
MenuComponent
]
})
add a comment |
You need to include all material modules in imports as well:
Shared Module
@NgModule({
imports: [CommonModule,
MatButtonModule,
MatSelectModule,
MatInputModule,
MatOptionModule,
MatToolbarModule
],
declarations: [MenuComponent],
exports: [
MatButtonModule,
MatSelectModule,
MatInputModule,
MatOptionModule,
MatToolbarModule,
MenuComponent
]
})
You need to include all material modules in imports as well:
Shared Module
@NgModule({
imports: [CommonModule,
MatButtonModule,
MatSelectModule,
MatInputModule,
MatOptionModule,
MatToolbarModule
],
declarations: [MenuComponent],
exports: [
MatButtonModule,
MatSelectModule,
MatInputModule,
MatOptionModule,
MatToolbarModule,
MenuComponent
]
})
answered Nov 15 '18 at 2:11
User3250User3250
1,6253928
1,6253928
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308677%2fshared-component-not-working-when-imported-into-lazy-loading-module%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
inside the shared module do you add the components to both declarations and exports?
– omer
Nov 14 '18 at 21:17
I didn't include them in the descriptions but I just saw, that some of the errors go away if I include them in the imports (It's also done like that in the app.module.ts)
– Fabio ha
Nov 14 '18 at 21:23
it doesn't sound right imports are for modules..
– omer
Nov 14 '18 at 21:25
Oh right yes, I see. The MenuComponent is in declarations and export. I was talking about the Angular Material modules
– Fabio ha
Nov 14 '18 at 21:27