Topic: how to run a function onclicking button in MDBootstrap (Angular)
Shashank Gour free asked 6 years ago
Hello Damian,
Please check the below code this is not working actually.
html
<button (click)="btnClick();" class="btn btn-primary" mdbRippleRadius>Get Your Quotation </button>
function
btnClick=function () {
this.router.navigateByUrl('contactus');
};
Regards,
Shashank
Damian Gemza staff answered 6 years ago
Dear Shashank,
In Typescript functions should look as follows:
1st way:
btnClick= () => { alert('Function was released'); };
2nd way:
btnClick() { alert('Function was released'); }
I've tested your function, but replaced this.router.navigateByUrl('contactus'); with alert(), and everything works fine. So there's something wrong with this.router.navigateByUrl('contactus');
If i could advice you something - if you need routing in your app, use Angular Routing: https://angular.io/guide/router
Best Regards,
Damian
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Status
Answered
Specification of the issue
- ForumUser: Free
- Premium support: No
- Technology: MDB Angular
- MDB Version: -
- Device: -
- Browser: -
- OS: -
- Provided sample code: No
- Provided link: No
Tags
Shashank Gour free commented 6 years ago
Damian, waiting for your reply ????Damian Gemza staff commented 6 years ago
Dear Shashank, Please notice that I do not constantly monitor the forum, but I am doing my best to help everyone. So if someone from our team doesn't reply to your ticket in few minutes, please wait patiently. Best Regards, Damian