Base Angular

by willseitz

HTML

<div ng-app="myApp">
    <div ng-controller="FormsCtrl">{{hello}}
        <button ng-click="preventLonliness()">Provide Love</button>
    </div>
</div>

CSS

</style> <!-- Ugly Hack to make remote files preload in jsFiddle --> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.min.js"></script> <style>

JavaScript

var myAppModule = angular.module('myApp', []);
myAppModule.controller('FormsCtrl', function ($scope, $timeout) {
    runAfterThisNotCalled = function (delay, func) {
        var myTimer;
        return function() {
            $timeout.cancel(myTimer);
            myTimer = $timeout(func, delay)
        }
    };

    $scope.hello = "hi";
    $scope.preventLonliness = runAfterThisNotCalled(2000, function () {
        $scope.hello = "no one loves me!";
    })
});