Skip to content

Instantly share code, notes, and snippets.

Created November 27, 2014 13:37
Show Gist options
  • Save anonymous/0bd27c47fa109c12e8bc to your computer and use it in GitHub Desktop.
Save anonymous/0bd27c47fa109c12e8bc to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html ng-app="App">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body ng-controller="MainCtrl">
<p>Angular 1.3</p>
<input type="text" ng-model="foo" ng-change="update()" ng-model-options="{debounce:3000}"><hr>
<p>Angular 1.2</p>
<input type="text" ng-model="foo" ng-change="onChange()"><hr>
<input type="text" ng-model="bar" ng-change="onChange()">
<script id="jsbin-javascript">
angular.module('App', [])
.controller('MainCtrl', function($scope, $timeout) {
$scope.foo = 'Foo';
$scope.bar = 'Bar';
$scope.update = function() {
console.log('Saved!');
};
function executeCommand(promise, waitMs, action) {
if (promise) {
$timeout.cancel(promise);
}
return $timeout(function() {
action();
}, waitMs);
}
function logTime() {
var date = new Date;
console.log("Last Change: " + date.getSeconds() + "." + date.getMilliseconds());
}
var ncPromise;
$scope.onChange = function() {
logTime();
ncPromise = executeCommand(ncPromise, 5000, function() {
console.log("Changing the name of the widget here.");
logTime();
});
};
});
</script>
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html>
<html ng-app="App">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"><\/script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body ng-controller="MainCtrl">
<p>Angular 1.3</p>
<input type="text" ng-model="foo" ng-change="update()" ng-model-options="{debounce:3000}"><hr>
<p>Angular 1.2</p>
<input type="text" ng-model="foo" ng-change="onChange()"><hr>
<input type="text" ng-model="bar" ng-change="onChange()">
</body>
</html></script>
<script id="jsbin-source-javascript" type="text/javascript">angular.module('App', [])
.controller('MainCtrl', function($scope, $timeout) {
$scope.foo = 'Foo';
$scope.bar = 'Bar';
$scope.update = function() {
console.log('Saved!');
};
function executeCommand(promise, waitMs, action) {
if (promise) {
$timeout.cancel(promise);
}
return $timeout(function() {
action();
}, waitMs);
}
function logTime() {
var date = new Date;
console.log("Last Change: " + date.getSeconds() + "." + date.getMilliseconds());
}
var ncPromise;
$scope.onChange = function() {
logTime();
ncPromise = executeCommand(ncPromise, 5000, function() {
console.log("Changing the name of the widget here.");
logTime();
});
};
});</script></body>
</html>
angular.module('App', [])
.controller('MainCtrl', function($scope, $timeout) {
$scope.foo = 'Foo';
$scope.bar = 'Bar';
$scope.update = function() {
console.log('Saved!');
};
function executeCommand(promise, waitMs, action) {
if (promise) {
$timeout.cancel(promise);
}
return $timeout(function() {
action();
}, waitMs);
}
function logTime() {
var date = new Date;
console.log("Last Change: " + date.getSeconds() + "." + date.getMilliseconds());
}
var ncPromise;
$scope.onChange = function() {
logTime();
ncPromise = executeCommand(ncPromise, 5000, function() {
console.log("Changing the name of the widget here.");
logTime();
});
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment