Angular Component part of two declarations
I created a small component which I want to use in some of the pages but I seem to have some problems when including it in more than one lazy load page.
add.button.component.ts
import { Component, Output, EventEmitter } from '@angular/core';
@Component({
selector: 'add-button',
template: `
<ion-buttons end>
<button ion-button icon-only (click)="navToAdd()">
<ion-icon name="md-add-circle"></ion-icon>
</button>
</ion-buttons>`
})
export class AddButton {
visible: boolean = true;
@Output() navigate: EventEmitter<any> = new EventEmitter();
navToAdd() {
this.navigate.emit(null)
}
}
app.modules.ts
import { BrowserModule } from '@angular/platform-browser';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { TabsPage } from '../pages/tabs/tabs';
@NgModule({
declarations: [
MyApp,
HomePage,
TabsPage
],
imports: [
BrowserModule,
...
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage,
TabsPage
],
providers: [
...
]
})
export class AppModule { }
users.module.ts - Just like users.module.ts
there are other page modules where I want to use the component just like i use it in users.module.ts
below
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { UsersPage } from './users';
import { AddButton } from '../../components/add-button.component';
@NgModule({
declarations: [
UsersPage,
AddButton
],
imports: [
IonicPageModule.forChild(UsersPage),
],
})
export class UsersPageModule { }
angular typescript ionic-framework ionic3
add a comment |
I created a small component which I want to use in some of the pages but I seem to have some problems when including it in more than one lazy load page.
add.button.component.ts
import { Component, Output, EventEmitter } from '@angular/core';
@Component({
selector: 'add-button',
template: `
<ion-buttons end>
<button ion-button icon-only (click)="navToAdd()">
<ion-icon name="md-add-circle"></ion-icon>
</button>
</ion-buttons>`
})
export class AddButton {
visible: boolean = true;
@Output() navigate: EventEmitter<any> = new EventEmitter();
navToAdd() {
this.navigate.emit(null)
}
}
app.modules.ts
import { BrowserModule } from '@angular/platform-browser';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { TabsPage } from '../pages/tabs/tabs';
@NgModule({
declarations: [
MyApp,
HomePage,
TabsPage
],
imports: [
BrowserModule,
...
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage,
TabsPage
],
providers: [
...
]
})
export class AppModule { }
users.module.ts - Just like users.module.ts
there are other page modules where I want to use the component just like i use it in users.module.ts
below
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { UsersPage } from './users';
import { AddButton } from '../../components/add-button.component';
@NgModule({
declarations: [
UsersPage,
AddButton
],
imports: [
IonicPageModule.forChild(UsersPage),
],
})
export class UsersPageModule { }
angular typescript ionic-framework ionic3
I would create a Common-Module for those Components and include the Module in both other modules
– enno.void
Nov 21 '18 at 13:00
add a comment |
I created a small component which I want to use in some of the pages but I seem to have some problems when including it in more than one lazy load page.
add.button.component.ts
import { Component, Output, EventEmitter } from '@angular/core';
@Component({
selector: 'add-button',
template: `
<ion-buttons end>
<button ion-button icon-only (click)="navToAdd()">
<ion-icon name="md-add-circle"></ion-icon>
</button>
</ion-buttons>`
})
export class AddButton {
visible: boolean = true;
@Output() navigate: EventEmitter<any> = new EventEmitter();
navToAdd() {
this.navigate.emit(null)
}
}
app.modules.ts
import { BrowserModule } from '@angular/platform-browser';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { TabsPage } from '../pages/tabs/tabs';
@NgModule({
declarations: [
MyApp,
HomePage,
TabsPage
],
imports: [
BrowserModule,
...
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage,
TabsPage
],
providers: [
...
]
})
export class AppModule { }
users.module.ts - Just like users.module.ts
there are other page modules where I want to use the component just like i use it in users.module.ts
below
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { UsersPage } from './users';
import { AddButton } from '../../components/add-button.component';
@NgModule({
declarations: [
UsersPage,
AddButton
],
imports: [
IonicPageModule.forChild(UsersPage),
],
})
export class UsersPageModule { }
angular typescript ionic-framework ionic3
I created a small component which I want to use in some of the pages but I seem to have some problems when including it in more than one lazy load page.
add.button.component.ts
import { Component, Output, EventEmitter } from '@angular/core';
@Component({
selector: 'add-button',
template: `
<ion-buttons end>
<button ion-button icon-only (click)="navToAdd()">
<ion-icon name="md-add-circle"></ion-icon>
</button>
</ion-buttons>`
})
export class AddButton {
visible: boolean = true;
@Output() navigate: EventEmitter<any> = new EventEmitter();
navToAdd() {
this.navigate.emit(null)
}
}
app.modules.ts
import { BrowserModule } from '@angular/platform-browser';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { TabsPage } from '../pages/tabs/tabs';
@NgModule({
declarations: [
MyApp,
HomePage,
TabsPage
],
imports: [
BrowserModule,
...
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage,
TabsPage
],
providers: [
...
]
})
export class AppModule { }
users.module.ts - Just like users.module.ts
there are other page modules where I want to use the component just like i use it in users.module.ts
below
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { UsersPage } from './users';
import { AddButton } from '../../components/add-button.component';
@NgModule({
declarations: [
UsersPage,
AddButton
],
imports: [
IonicPageModule.forChild(UsersPage),
],
})
export class UsersPageModule { }
angular typescript ionic-framework ionic3
angular typescript ionic-framework ionic3
edited Nov 21 '18 at 15:15
Octavio Garbarino
472511
472511
asked Nov 21 '18 at 12:58
CiprianCiprian
74922558
74922558
I would create a Common-Module for those Components and include the Module in both other modules
– enno.void
Nov 21 '18 at 13:00
add a comment |
I would create a Common-Module for those Components and include the Module in both other modules
– enno.void
Nov 21 '18 at 13:00
I would create a Common-Module for those Components and include the Module in both other modules
– enno.void
Nov 21 '18 at 13:00
I would create a Common-Module for those Components and include the Module in both other modules
– enno.void
Nov 21 '18 at 13:00
add a comment |
4 Answers
4
active
oldest
votes
Your AddButton should probably be on a Shared module and then you would be able to use it in multiple places by importing the module
Ok ... Seems simple enough to create a shared module. I don't know where to include it. Do I include the shared module in all page modules? Likeusers.module.ts
,events.module.ts
? What shouldusers.module.ts
look like?
– Ciprian
Nov 21 '18 at 13:23
add a comment |
add your AddButton
component into exports
array of users.module.ts
so you can use it in other modules where UsersModule
is imported
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { UsersPage } from './users';
import { AddButton } from '../../components/add-button.component';
@NgModule({
declarations: [
UsersPage,
AddButton
],
imports: [
IonicPageModule.forChild(UsersPage),
],
exports: [
AddButton
]
})
export class UsersPageModule { }
add a comment |
If you create the component with the ionic cli
with ionic g component AddButton it will automatically create a ComponentsModule and your new component in that module.
And to use this component in the other modules you just have to import that module in the modules that you need.
Also in your ComponentModule you should add imports: [IonicModule]
in order to be able to use the Ionic Components like ion-buttons
add a comment |
If you think ButtonComponent doesn't fit to be in Shared Module, Make a Individual module for AddButton
. Now this new module should declare and export the AddButtonComponent
. You should import this new module in whichever child module you want it to be used for. This should not cause any problem. This will also save you from loading all Shared component just for sake of getting AddComponent
working.
It's a best practice to create another module for the component if it is being used at multiple places/modules.
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%2f53412562%2fangular-component-part-of-two-declarations%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your AddButton should probably be on a Shared module and then you would be able to use it in multiple places by importing the module
Ok ... Seems simple enough to create a shared module. I don't know where to include it. Do I include the shared module in all page modules? Likeusers.module.ts
,events.module.ts
? What shouldusers.module.ts
look like?
– Ciprian
Nov 21 '18 at 13:23
add a comment |
Your AddButton should probably be on a Shared module and then you would be able to use it in multiple places by importing the module
Ok ... Seems simple enough to create a shared module. I don't know where to include it. Do I include the shared module in all page modules? Likeusers.module.ts
,events.module.ts
? What shouldusers.module.ts
look like?
– Ciprian
Nov 21 '18 at 13:23
add a comment |
Your AddButton should probably be on a Shared module and then you would be able to use it in multiple places by importing the module
Your AddButton should probably be on a Shared module and then you would be able to use it in multiple places by importing the module
answered Nov 21 '18 at 13:03
BrunoLMBrunoLM
60.8k67228389
60.8k67228389
Ok ... Seems simple enough to create a shared module. I don't know where to include it. Do I include the shared module in all page modules? Likeusers.module.ts
,events.module.ts
? What shouldusers.module.ts
look like?
– Ciprian
Nov 21 '18 at 13:23
add a comment |
Ok ... Seems simple enough to create a shared module. I don't know where to include it. Do I include the shared module in all page modules? Likeusers.module.ts
,events.module.ts
? What shouldusers.module.ts
look like?
– Ciprian
Nov 21 '18 at 13:23
Ok ... Seems simple enough to create a shared module. I don't know where to include it. Do I include the shared module in all page modules? Like
users.module.ts
, events.module.ts
? What should users.module.ts
look like?– Ciprian
Nov 21 '18 at 13:23
Ok ... Seems simple enough to create a shared module. I don't know where to include it. Do I include the shared module in all page modules? Like
users.module.ts
, events.module.ts
? What should users.module.ts
look like?– Ciprian
Nov 21 '18 at 13:23
add a comment |
add your AddButton
component into exports
array of users.module.ts
so you can use it in other modules where UsersModule
is imported
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { UsersPage } from './users';
import { AddButton } from '../../components/add-button.component';
@NgModule({
declarations: [
UsersPage,
AddButton
],
imports: [
IonicPageModule.forChild(UsersPage),
],
exports: [
AddButton
]
})
export class UsersPageModule { }
add a comment |
add your AddButton
component into exports
array of users.module.ts
so you can use it in other modules where UsersModule
is imported
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { UsersPage } from './users';
import { AddButton } from '../../components/add-button.component';
@NgModule({
declarations: [
UsersPage,
AddButton
],
imports: [
IonicPageModule.forChild(UsersPage),
],
exports: [
AddButton
]
})
export class UsersPageModule { }
add a comment |
add your AddButton
component into exports
array of users.module.ts
so you can use it in other modules where UsersModule
is imported
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { UsersPage } from './users';
import { AddButton } from '../../components/add-button.component';
@NgModule({
declarations: [
UsersPage,
AddButton
],
imports: [
IonicPageModule.forChild(UsersPage),
],
exports: [
AddButton
]
})
export class UsersPageModule { }
add your AddButton
component into exports
array of users.module.ts
so you can use it in other modules where UsersModule
is imported
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { UsersPage } from './users';
import { AddButton } from '../../components/add-button.component';
@NgModule({
declarations: [
UsersPage,
AddButton
],
imports: [
IonicPageModule.forChild(UsersPage),
],
exports: [
AddButton
]
})
export class UsersPageModule { }
answered Nov 21 '18 at 13:03
Artyom AmiryanArtyom Amiryan
1,9621215
1,9621215
add a comment |
add a comment |
If you create the component with the ionic cli
with ionic g component AddButton it will automatically create a ComponentsModule and your new component in that module.
And to use this component in the other modules you just have to import that module in the modules that you need.
Also in your ComponentModule you should add imports: [IonicModule]
in order to be able to use the Ionic Components like ion-buttons
add a comment |
If you create the component with the ionic cli
with ionic g component AddButton it will automatically create a ComponentsModule and your new component in that module.
And to use this component in the other modules you just have to import that module in the modules that you need.
Also in your ComponentModule you should add imports: [IonicModule]
in order to be able to use the Ionic Components like ion-buttons
add a comment |
If you create the component with the ionic cli
with ionic g component AddButton it will automatically create a ComponentsModule and your new component in that module.
And to use this component in the other modules you just have to import that module in the modules that you need.
Also in your ComponentModule you should add imports: [IonicModule]
in order to be able to use the Ionic Components like ion-buttons
If you create the component with the ionic cli
with ionic g component AddButton it will automatically create a ComponentsModule and your new component in that module.
And to use this component in the other modules you just have to import that module in the modules that you need.
Also in your ComponentModule you should add imports: [IonicModule]
in order to be able to use the Ionic Components like ion-buttons
answered Nov 21 '18 at 13:07
Octavio GarbarinoOctavio Garbarino
472511
472511
add a comment |
add a comment |
If you think ButtonComponent doesn't fit to be in Shared Module, Make a Individual module for AddButton
. Now this new module should declare and export the AddButtonComponent
. You should import this new module in whichever child module you want it to be used for. This should not cause any problem. This will also save you from loading all Shared component just for sake of getting AddComponent
working.
It's a best practice to create another module for the component if it is being used at multiple places/modules.
add a comment |
If you think ButtonComponent doesn't fit to be in Shared Module, Make a Individual module for AddButton
. Now this new module should declare and export the AddButtonComponent
. You should import this new module in whichever child module you want it to be used for. This should not cause any problem. This will also save you from loading all Shared component just for sake of getting AddComponent
working.
It's a best practice to create another module for the component if it is being used at multiple places/modules.
add a comment |
If you think ButtonComponent doesn't fit to be in Shared Module, Make a Individual module for AddButton
. Now this new module should declare and export the AddButtonComponent
. You should import this new module in whichever child module you want it to be used for. This should not cause any problem. This will also save you from loading all Shared component just for sake of getting AddComponent
working.
It's a best practice to create another module for the component if it is being used at multiple places/modules.
If you think ButtonComponent doesn't fit to be in Shared Module, Make a Individual module for AddButton
. Now this new module should declare and export the AddButtonComponent
. You should import this new module in whichever child module you want it to be used for. This should not cause any problem. This will also save you from loading all Shared component just for sake of getting AddComponent
working.
It's a best practice to create another module for the component if it is being used at multiple places/modules.
answered Nov 21 '18 at 13:33
nircraftnircraft
1,702521
1,702521
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%2f53412562%2fangular-component-part-of-two-declarations%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
I would create a Common-Module for those Components and include the Module in both other modules
– enno.void
Nov 21 '18 at 13:00