My code is as under:
HTML
<section ng-controller="randController as rand">
Skriv inn minimumtall:<br>
<input ng-model="rand.minimum" type="number" placeholder="Minste tall"><br>
<div class="tiny"></div>
Skriv inn makstall:<br>
<input ng-model="rand.maksimum" type="number" placeholder="Største tall"><br><br>
<ul class="nav nav-pills" ng-controller="clickController as click">
<li ng-click="click.randClick()" ng-class="{'active' : click.randCheck(true)}" >
<a ng-click="rand.tilfeldig()">Randomize!</a>
</li>
</ul>
<div class="tiny"></div><br>
<pre>Tilfeldig tall = {{rand.tilfeldig()}}</pre>
</section>
JS
.controller('clickController', function ($timeout) {
this.randClicked = false;
this.randClick = function () {
this.randClicked = true;
$timeout(function() {
this.randClicked = false;
}, 1000, true);
};
this.randCheck = function (x) {
return this.randClicked === x;
};
})
What I am trying to do is to reset the active class of the <li>
-element after about 2 seconds (Unclick it after it has been clicked for 2 seconds). I have gotten tips from forum members but it still doesn't work. Currently, I get this error, which I don't understand.