NodeGuy / server-date

Make the server's clock available in the browser.
http://www.nodeguy.com/serverdate/
Mozilla Public License 2.0
193 stars 52 forks source link

Usage with Angular 6 #36

Closed sapanjwani closed 5 years ago

sapanjwani commented 5 years ago

Your code and the idea is very good. Is there a way to use this with Angular 6 framework . I was trying to make a service which returns the ServerDate.now() ; which can be used by other components and services . Thanks, Awaiting your help !

NodeGuy commented 5 years ago

Thank you. I'm not familiar with Angular 6 but I don't see why ServerDate couldn't be incorporated into a component. If you try and run into a problem you're welcome to post code here and I can see if I can help.

sapanjwani commented 5 years ago

I added serverDate.js by adding it as a script on document body like this . loadScript() { const body = document.body; const script = document.createElement('script'); script.innerHTML = ''; script.src = '../assets/js/ServerDate.js'; body.appendChild(script); } And then used like this. this.serverDateTimeStamp = (window as any).ServerDate.now(); This seemed working fine for me . Are there any suggestions ? I welcome your suggestions.

NodeGuy commented 5 years ago

Looks good to me. :-)