gpt4 book ai didi

angular5 - 找不到模块 'timers'

转载 作者:行者123 更新时间:2023-12-03 06:42:32 25 4
gpt4 key购买 nike

我在 users.component.ts 中使用 setTimeout 方法,但不起作用并获取找不到模块“计时器”错误

我导入此代码但不起作用

import { setTimeout } from 'timers'

最佳答案

我使用了SetInterval函数,还删除了自动生成的导入语句。

例如:

import { Component, OnInit } from '@angular/core';
//import { setInterval } from 'timers';

export class HelloWorldComponent implements OnInit {

message : string ;
constructor() {

setInterval(() => {
let currentDate = new Date();
this.message = currentDate.toDateString() + " " + currentDate.toLocaleTimeString();
}, 1000);
}

ngOnInit() {
}

}

关于angular5 - 找不到模块 'timers',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50136805/

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