gpt4 book ai didi

angular - 如何在html中调用 Angular 方法?

转载 作者:行者123 更新时间:2023-12-05 03:59:11 24 4
gpt4 key购买 nike

我有一个返回整数的 Angular 函数。我想要的只是在 html 中调用这个函数。我怎样才能做到这一点?

我在 html 中尝试了两种数据绑定(bind)方式,例如 {{functionname()}} 来调用函数,但这没有用。这是我的函数:

getTodaysOrder(){
return this.http.get(this.url+'/GetTodaysOrder').subscribe(data => {
this.formData = data as number;
});
}

最佳答案

如果要在页面加载时调用函数,请在 OnInit 中添加函数

OnInit(){
this.getTodaysOrder();
}

getTodaysOrder(){
return this.http.get(this.url+'/GetTodaysOrder').subscribe(data => {
this.formData = data as number;
});
}

关于angular - 如何在html中调用 Angular 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57466579/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com