angular-shepherd: Custom action on button not working
So I just get started using Shepherd on my Angular 8 project, unfortunately, I can’t do any custom actions inside my buttons.
builtInButtons = {
complete: {
classes: "finish-button",
secondary: false,
text: "Ok",
type: "cancel",
action() {
console.log('finishing my tour')
},
},
next: {
classes: "next-button",
text: "Next",
type: "next"
},
back: {
classes: "back-button",
secondary: true,
text: "Back",
type: "back"
}
};
console.log() doesn’t happen, and I can’t see why. Basically what I’m seeking is a way to router.navigate when the user finishes the current tour by clicking or advancing via keyboard.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 2
- Comments: 15 (5 by maintainers)
Ok, apparently you can’t have a type and an action on the same button. Removing the type “cancel” solved it. I don’t know if this is intended, maybe we need this in the docs.
@rwwagner90 You are absolutely right, worked like a charm - got a headache from figuring out a way to access service-scoped variables inside the button action - and this is exactly how you do it. Thank you!
@yc-98 it’s a scoping issue.
thisinside the action points to the tour.Try this:
As a last resort, you could define a variable for the router.
Does this make sense?
Yes, it does seem we do not document the button types well. Would you be interested in opening a PR?