I'm using angular version 17.2.0
. And in the service
import { Injectable } from '@angular/core';
import { Signal, ReadOnlySignal } from '@angular/core';
@Injectable({
providedIn: 'root' // Make the service available throughout the application
})
export class CurrentTimeService {
private currentTimeInSeconds = new Signal<number>(); // throw Error in this line.
}
}
I want to create a service in the latest angular version 17.2.0
for getting currentTime based on in Angular signal
As the error says, we need to define the signal with a small first letter signal
instead of Signal
(type). Also we don't need to use new
!
import { Injectable, signal } from '@angular/core';
import { Signal } from '@angular/core';
@Injectable({
providedIn: 'root',
})
export class CurrentTimeService {
private currentTimeInSeconds = signal<number>(0);
constructor() {}
}