Created
November 27, 2014 13:37
-
-
Save anonymous/0bd27c47fa109c12e8bc to your computer and use it in GitHub Desktop.
// source http://jsbin.com/tunojonoka
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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