我正在尝试为我的宠物项目实现新功能。
基本上我有这个功能:
public makePayment() {
const url = 'http://localhost:8080/';
return this.http.post(url + 'paypal/make/payment?sum=8', {}).subscribe(res => console.log(JSON.stringify(res)));
}
我不想在这里调用它:
<a [routerLink]="makePayment()">MAKE A DEPOSIT</a>
但是,它在页面加载时被调用,并开始向我的后端发送请求垃圾邮件。
我做了几次类似的事情,而且效果很好。您能帮我理解问题吗?
答案 0 :(得分:2)
路由链接用于导航,而不是调用函数。请尝试以下方法:
http://localhost:3000
这不会像链接那样设置样式,您必须为此添加css。