Adding simple Service provider cause error

No NgModule metadata found for ‘undefined’.

this error happend just after adding provider on app.module.ts…

app.module.ts


import { TimeService } from './../shared/time'
providers: [
    TimeService,
....
...
]

TimeService.ts

import { Subscription } from 'rxjs/Rx';
import { Http } from '@angular/http';
import { Injectable } from '@angular/core';
@Injectable()
export class TimeService{
    
    constructor(){
        console.log("TimeService!");

    }
    getTime(){
        let today = new Date();
        let dd:number;
        let day:string;
        let month:string;
         dd = today.getDate();
        var mm = today.getMonth()+1; //January is 0!

        var yyyy = today.getFullYear();
       var time=new Date().toLocaleTimeString('en-US', { hour12: false,hour: "numeric",minute: "numeric"});
        dd<10?day='0'+dd:day=''+dd;
        mm<10?month='0'+mm:month=''+mm;
        let todaywithTime = mm+"/"+dd+"/"+time;
        let todayNoTime= yyyy+" "+mm+" "+dd;

        return todaywithTime;
    }
}

I want this timeservice to use like below.

home. ts

constructor(public time:TimeService){
 this.time.getTime()
}

You have no trailing comma after the end of your providers array. If that’s the case in your actual app module, you’ve probably broken its syntax.

Incidentally, you shouldn’t reinvent the wheel like this. Use date-fns/format and your entire getTime() method becomes one simple line (and you get easy i18n for free).