gpt4 book ai didi

javascript - Angular : Update A Function In RealTime

转载 作者:数据小太阳 更新时间:2023-10-29 05:46:48 25 4
gpt4 key购买 nike

我有一个 Controller :

$scope.timeAgoCreation = function(order) {
return moment(order.createdAt).fromNow();
};

在 View 中:

{{timeAgoCreation(order)}}

它返回正确的值:9 分钟前。但是这个值不是实时更新的。我必须刷新页面。

是否可以让它实时更新?

最佳答案

只需将此功能添加到 Controller 中(不要忘记注入(inject) $timeout 服务):

function fireDigestEverySecond() {
$timeout(fireDigestEverySecond , 1000);
};
fireDigestEverySecond();

$timeout 在作为第一个参数传入的函数被调用后自动触发摘要循环,因此 View 中的值应该每秒更新一次。

你在那里工作 jsFiddle .

关于javascript - Angular : Update A Function In RealTime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17641278/

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