How do I connect this interval service to a view?

First, you didn’t inject the $interval to the mytimer service and did try to use it.

secondly, you had scope issues in the mytimer service:

stop = $interval(function() {
    if (this.blood_1 > 0 && this.blood_2 > 0) {
        this.blood_1 = $this.blood_1 - 3;
        this.blood_2 = $this.blood_2 - 4;
    } else {
        this.stopFight();
    }
}, 100);

when declaring a function you are creating a new scope, meaning the this is pointing to a new scope. you can either use bind or to use the $this variable you declared in line 5. (in ES2015 you could simply use the arrow function).

also you declared the module exampleController twice in app.js and in mytimer.js.

Take a look at this working Plunker:
http://plnkr.co/edit/34rlsjzH5KWaobiungYI?p=preview

Leave a Comment