1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

The SetInterval function does'nt work in Angular 17

Discussão em 'Angular' iniciado por Fotso Rostand, Setembro 11, 2024 às 11:02.

  1. When i use setInterval in Angular the browser doesnt load the content anymore. This problem just happens in Angular 17. I dont know if im the only one with this or if nobody in Google or in Angular community notice, that there is a problem with the setInterval.

    import { AfterViewInit, Component, OnInit, inject } from '@angular/core';
    import { CarService } from '../services/cars.service';
    import { Car } from '../interfaces/car';

    @Component({
    selector: 'app-count-cars',
    standalone: true,
    imports: [],
    templateUrl: './count-cars.component.html',
    styleUrl: './count-cars.component.scss'
    })
    export class CountCarsComponent implements AfterViewInit {
    carService: CarService = inject(CarService)
    cars: Car[] = []
    carsNumber = 0;
    constructor() {
    this.cars = this.carService.getCars();
    this.carsNumber = this.cars.length;
    }
    ngAfterViewInit(): void {
    setInterval(()=> {
    this.cars = this.carService.getCars();
    this.carsNumber = this.cars.length;
    }, 10000)
    }
    }



    Everything works well without setIntervall.

    Continue reading...

Compartilhe esta Página