dman
dman

Reputation: 11064

Angular.js Template Function Not Running

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;

Upvotes: 0

Views: 57

Answers (1)

Chris Preston
Chris Preston

Reputation: 634

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.

Upvotes: 1

Related Questions