export class ServerComponent implements OnInit {
show = false;
setTimeout(() => {
this.show = true;
}, 2000);
constructor(){
}
ngOnInit(){
}
}
CodePudding user response:
You cannot put setTimeout or anything that isn't a property of method inside a class definition.
Make sure you understand Classes properly!
The right way to do this would be to put the setTimeout
inside your constructor function
CodePudding user response:
Set timeout is basically a prebuilt library function (method) with two parameters.
- callback function
- timeout in milliseconds
so what you trying to do is calling a existing library function outside a method or constructor which is not allowed.