To call different dialog window based on the button present in the component












0














I have a component called home which as some description and button inside it. As in below image.



enter image description here




  • I am reusing the same home component in another 2 components called car and bike.


  • Here in car component on clicking the button (i,e button present in the home component), I am calling a component called car-booking inside a dialog window. This requirement is done now.


  • But I am re-using home component in bike component too. In bike component on clicking the button(i,e button present in the home component) I should call another component (ex bike-booking) inside the dialog window.



How can I change the (click) function of the particular button on basis of its presence in the component?



The stackblitz DEMO










share|improve this question
























  • Could you provide your code here rather than a link.
    – Wojtek T
    Nov 12 '18 at 10:43










  • The components are more , to post the code.so i created the stackblitz link Please see the stackblitz link. Any doubts arises i will tell you.
    – Shankar guru
    Nov 12 '18 at 10:45
















0














I have a component called home which as some description and button inside it. As in below image.



enter image description here




  • I am reusing the same home component in another 2 components called car and bike.


  • Here in car component on clicking the button (i,e button present in the home component), I am calling a component called car-booking inside a dialog window. This requirement is done now.


  • But I am re-using home component in bike component too. In bike component on clicking the button(i,e button present in the home component) I should call another component (ex bike-booking) inside the dialog window.



How can I change the (click) function of the particular button on basis of its presence in the component?



The stackblitz DEMO










share|improve this question
























  • Could you provide your code here rather than a link.
    – Wojtek T
    Nov 12 '18 at 10:43










  • The components are more , to post the code.so i created the stackblitz link Please see the stackblitz link. Any doubts arises i will tell you.
    – Shankar guru
    Nov 12 '18 at 10:45














0












0








0







I have a component called home which as some description and button inside it. As in below image.



enter image description here




  • I am reusing the same home component in another 2 components called car and bike.


  • Here in car component on clicking the button (i,e button present in the home component), I am calling a component called car-booking inside a dialog window. This requirement is done now.


  • But I am re-using home component in bike component too. In bike component on clicking the button(i,e button present in the home component) I should call another component (ex bike-booking) inside the dialog window.



How can I change the (click) function of the particular button on basis of its presence in the component?



The stackblitz DEMO










share|improve this question















I have a component called home which as some description and button inside it. As in below image.



enter image description here




  • I am reusing the same home component in another 2 components called car and bike.


  • Here in car component on clicking the button (i,e button present in the home component), I am calling a component called car-booking inside a dialog window. This requirement is done now.


  • But I am re-using home component in bike component too. In bike component on clicking the button(i,e button present in the home component) I should call another component (ex bike-booking) inside the dialog window.



How can I change the (click) function of the particular button on basis of its presence in the component?



The stackblitz DEMO







angular typescript angular-material angular6






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 '18 at 12:08









Yashwardhan Pauranik

1,82011227




1,82011227










asked Nov 12 '18 at 10:34









Shankar guru

4171319




4171319












  • Could you provide your code here rather than a link.
    – Wojtek T
    Nov 12 '18 at 10:43










  • The components are more , to post the code.so i created the stackblitz link Please see the stackblitz link. Any doubts arises i will tell you.
    – Shankar guru
    Nov 12 '18 at 10:45


















  • Could you provide your code here rather than a link.
    – Wojtek T
    Nov 12 '18 at 10:43










  • The components are more , to post the code.so i created the stackblitz link Please see the stackblitz link. Any doubts arises i will tell you.
    – Shankar guru
    Nov 12 '18 at 10:45
















Could you provide your code here rather than a link.
– Wojtek T
Nov 12 '18 at 10:43




Could you provide your code here rather than a link.
– Wojtek T
Nov 12 '18 at 10:43












The components are more , to post the code.so i created the stackblitz link Please see the stackblitz link. Any doubts arises i will tell you.
– Shankar guru
Nov 12 '18 at 10:45




The components are more , to post the code.so i created the stackblitz link Please see the stackblitz link. Any doubts arises i will tell you.
– Shankar guru
Nov 12 '18 at 10:45












1 Answer
1






active

oldest

votes


















1














You can use @Output to emit an event to the container, then in the container component you can choose what to do when you receive the event.



HomeComponent



export class HomeComponent  {

@Output() openDialog = new EventEmitter();

constructor(public dialog: MatDialog) {}

open(): void {
this.openDialog.emit();
}

}


HomeComponent's template



Hai!! welcome to our application..

<div style="padding:30px;">
<button mat-raised-button (click)="open()" color="primary">ADD</button>
</div>


BikeComponent's template



<app-home (openDialog)="openDialog($event)"></app-home>


BikeComponent ts



export class BikeComponent implements OnInit {

constructor() { }

ngOnInit() {
}

openDialog($event: any) {
// open desired bike component
}

}


CarComponent's template



<app-home (openDialog)="openDialog($event)"></app-home>


CarComponent ts



export class CarComponent implements OnInit {

constructor() { }

ngOnInit() {
}

openDialog($event: any) {
// open desired car component
}

}


Look at official doc: https://angular.io/guide/component-interaction






share|improve this answer























  • I am getting this ERROR: _co.openDialog is not a function
    – Shankar guru
    Nov 12 '18 at 10:57










  • let's try now please
    – firegloves
    Nov 12 '18 at 11:02










  • Thanks a lot!! you have saved my day.
    – Shankar guru
    Nov 12 '18 at 11:08











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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53260319%2fto-call-different-dialog-window-based-on-the-button-present-in-the-component%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









1














You can use @Output to emit an event to the container, then in the container component you can choose what to do when you receive the event.



HomeComponent



export class HomeComponent  {

@Output() openDialog = new EventEmitter();

constructor(public dialog: MatDialog) {}

open(): void {
this.openDialog.emit();
}

}


HomeComponent's template



Hai!! welcome to our application..

<div style="padding:30px;">
<button mat-raised-button (click)="open()" color="primary">ADD</button>
</div>


BikeComponent's template



<app-home (openDialog)="openDialog($event)"></app-home>


BikeComponent ts



export class BikeComponent implements OnInit {

constructor() { }

ngOnInit() {
}

openDialog($event: any) {
// open desired bike component
}

}


CarComponent's template



<app-home (openDialog)="openDialog($event)"></app-home>


CarComponent ts



export class CarComponent implements OnInit {

constructor() { }

ngOnInit() {
}

openDialog($event: any) {
// open desired car component
}

}


Look at official doc: https://angular.io/guide/component-interaction






share|improve this answer























  • I am getting this ERROR: _co.openDialog is not a function
    – Shankar guru
    Nov 12 '18 at 10:57










  • let's try now please
    – firegloves
    Nov 12 '18 at 11:02










  • Thanks a lot!! you have saved my day.
    – Shankar guru
    Nov 12 '18 at 11:08
















1














You can use @Output to emit an event to the container, then in the container component you can choose what to do when you receive the event.



HomeComponent



export class HomeComponent  {

@Output() openDialog = new EventEmitter();

constructor(public dialog: MatDialog) {}

open(): void {
this.openDialog.emit();
}

}


HomeComponent's template



Hai!! welcome to our application..

<div style="padding:30px;">
<button mat-raised-button (click)="open()" color="primary">ADD</button>
</div>


BikeComponent's template



<app-home (openDialog)="openDialog($event)"></app-home>


BikeComponent ts



export class BikeComponent implements OnInit {

constructor() { }

ngOnInit() {
}

openDialog($event: any) {
// open desired bike component
}

}


CarComponent's template



<app-home (openDialog)="openDialog($event)"></app-home>


CarComponent ts



export class CarComponent implements OnInit {

constructor() { }

ngOnInit() {
}

openDialog($event: any) {
// open desired car component
}

}


Look at official doc: https://angular.io/guide/component-interaction






share|improve this answer























  • I am getting this ERROR: _co.openDialog is not a function
    – Shankar guru
    Nov 12 '18 at 10:57










  • let's try now please
    – firegloves
    Nov 12 '18 at 11:02










  • Thanks a lot!! you have saved my day.
    – Shankar guru
    Nov 12 '18 at 11:08














1












1








1






You can use @Output to emit an event to the container, then in the container component you can choose what to do when you receive the event.



HomeComponent



export class HomeComponent  {

@Output() openDialog = new EventEmitter();

constructor(public dialog: MatDialog) {}

open(): void {
this.openDialog.emit();
}

}


HomeComponent's template



Hai!! welcome to our application..

<div style="padding:30px;">
<button mat-raised-button (click)="open()" color="primary">ADD</button>
</div>


BikeComponent's template



<app-home (openDialog)="openDialog($event)"></app-home>


BikeComponent ts



export class BikeComponent implements OnInit {

constructor() { }

ngOnInit() {
}

openDialog($event: any) {
// open desired bike component
}

}


CarComponent's template



<app-home (openDialog)="openDialog($event)"></app-home>


CarComponent ts



export class CarComponent implements OnInit {

constructor() { }

ngOnInit() {
}

openDialog($event: any) {
// open desired car component
}

}


Look at official doc: https://angular.io/guide/component-interaction






share|improve this answer














You can use @Output to emit an event to the container, then in the container component you can choose what to do when you receive the event.



HomeComponent



export class HomeComponent  {

@Output() openDialog = new EventEmitter();

constructor(public dialog: MatDialog) {}

open(): void {
this.openDialog.emit();
}

}


HomeComponent's template



Hai!! welcome to our application..

<div style="padding:30px;">
<button mat-raised-button (click)="open()" color="primary">ADD</button>
</div>


BikeComponent's template



<app-home (openDialog)="openDialog($event)"></app-home>


BikeComponent ts



export class BikeComponent implements OnInit {

constructor() { }

ngOnInit() {
}

openDialog($event: any) {
// open desired bike component
}

}


CarComponent's template



<app-home (openDialog)="openDialog($event)"></app-home>


CarComponent ts



export class CarComponent implements OnInit {

constructor() { }

ngOnInit() {
}

openDialog($event: any) {
// open desired car component
}

}


Look at official doc: https://angular.io/guide/component-interaction







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 12 '18 at 11:02

























answered Nov 12 '18 at 10:48









firegloves

3,22511025




3,22511025












  • I am getting this ERROR: _co.openDialog is not a function
    – Shankar guru
    Nov 12 '18 at 10:57










  • let's try now please
    – firegloves
    Nov 12 '18 at 11:02










  • Thanks a lot!! you have saved my day.
    – Shankar guru
    Nov 12 '18 at 11:08


















  • I am getting this ERROR: _co.openDialog is not a function
    – Shankar guru
    Nov 12 '18 at 10:57










  • let's try now please
    – firegloves
    Nov 12 '18 at 11:02










  • Thanks a lot!! you have saved my day.
    – Shankar guru
    Nov 12 '18 at 11:08
















I am getting this ERROR: _co.openDialog is not a function
– Shankar guru
Nov 12 '18 at 10:57




I am getting this ERROR: _co.openDialog is not a function
– Shankar guru
Nov 12 '18 at 10:57












let's try now please
– firegloves
Nov 12 '18 at 11:02




let's try now please
– firegloves
Nov 12 '18 at 11:02












Thanks a lot!! you have saved my day.
– Shankar guru
Nov 12 '18 at 11:08




Thanks a lot!! you have saved my day.
– Shankar guru
Nov 12 '18 at 11:08


















draft saved

draft discarded




















































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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53260319%2fto-call-different-dialog-window-based-on-the-button-present-in-the-component%23new-answer', 'question_page');
}
);

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







這個網誌中的熱門文章

Academy of Television Arts & Sciences

L'Équipe

1995 France bombings