Implementing Simple Time Service
In this example you will build a simple time service that generates a local time object for different cities. Then in the AngularJS template you will use the time service in multiple controllers. The purpose is to give you a chance to see how easy it is to reuse an AngularJS service.
The code in Listing 10.3 implements a custom service named TimeService
using the function TimeObj()
to generate the service object. The code in TimeObj
simply defines a list of cities with a time zone offset and provides the getTZDate()
function to return a JavaScript Date object for a specific city. The getCities()
function creates an array of the cities represented and returns it.
Notice that there are several controllers added ...
Get Learning AngularJS now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.