0

I am writing a client side clock that ticks in Angular.js. However, nothing is showing up. For conventions, I wanted the clock to be a service injected into the controller.

html:

 <small>Current time is: {{ clientClock.now() | date: 'mediumTime' }} </small>

service:

angular.module('monitorApp')
.factory('clockTicker', function($interval) {
    $interval(function(){ }, 1000);
    return {
            clientClock: function() { return Date; }
    }
});

controller:

$scope.clientClock = clockTicker.clientClock;
4
  • 1
    since your clientClock is a function in the factory, try $scope.clientClock = clockTicker.clientClock(); note the parentheses at the end Commented Jul 6, 2014 at 4:36
  • 1
    was on to the solution and created a fiddler. A bit late though jsfiddle.net/4vXSt Commented Jul 6, 2014 at 4:46
  • 1
    @Chris Preston - why not submit your solution as an answer? Commented Jul 9, 2014 at 3:56
  • @BradWerth - good idea, so this question can be closed. Just added it. Commented Jul 10, 2014 at 0:23

1 Answer 1

1

The reason that doesn't work is because ClientClock inside the factory is a function, therefore it has to be called like this:

$scope.clientClock = clockTicker.clientClock(); 

note the parentheses at the end.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.