Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find module 'timers'

Tags:

angular5

i use method setTimeout in my users.component.ts but does not work and get cannot find module 'timers' error

i import this code but does not work

import { setTimeout } from 'timers'
like image 432
Zahra Avatar asked May 02 '18 14:05

Zahra


2 Answers

I have used SetInterval function, Also remove the import statement that is autogenerated.

Ex :

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() {
}

}
like image 171
shriyansh jain Avatar answered Dec 06 '22 20:12

shriyansh jain


Whenever you are using the setTimeout in our code,import { setTimeout } from 'timers' then this import we will get by autogenerating code, once remove this import statement and run the code it should work, for me working fine. `

like image 37
Srikanth Janapati Avatar answered Dec 06 '22 21:12

Srikanth Janapati