As I'm currently trying to make a smart mirror system based on angularJS, I started making a clock component as basic. Having done a bit of angular before, but not using component structure, I decided to give that a shot.
The angularJS component tutorial quickly learned me to not use $scope, but this instead, I wrote my component as follows:
angular
.module('smartMirrorFrontend', [])
.component('clock', {
template: '<div class="iface-component" id="component-clock">' +
'<h1>Clock component Angular</h1>' +
'<span id="clock-hours" >{{ $ctrl.hh }}</span>:' +
'<span id="clock-minutes">{{ $ctrl.mm }}</span>:' +
'<span id="clock-seconds">{{ $ctrl.ss }}</span>' +
'</div>',
controller: function ClockController($interval){
this.hh = this.mm = this.ss = null;
this.clock = function (){
const d = new Date();
this.hh = ('0' + d.getHours()).slice(-2);
this.mm = ('0' + d.getMinutes()).slice(-2);
this.ss = ('0' + d.getSeconds()).slice(-2);
};
this.clock();
$interval(this.clock, 1000);
}
});
Now, this all works perfectly fine, besides the fact that neither $interval nor $timeout seem to be able to fire my function every second.
Here's the small catch: I have checked out other AngularJS clock questions on stackoverflow, but none implement it in the this style, and are using $scope instead. They also just place the values in one span, while I need this clock to be able to stand in vertical mode (so top to bottom) in separate spans (as seen in the template part)
The console in the webbrowser is not showing any problems, the component displays and loads the time once and correctly, meaning the function does fire once as it should. The component is inserted in the html using <clock></clock>
My question being: Why is my interval not working as it should be, and how can I make it work?