Awesome
ng-command
Command Pattern implementation for AngularJS.
bower install ng-command
Demo
Summary
ng-command
lets you write commands which can only execute once whilst executing and also if canExecute
is met.
Example
var app = angular.module('commandLab', ['ng-command'])
.controller('CommandExampleCtrl', ['$command', '$scope', '$timeout',
function ($command, $scope, $timeout) {
var self = this;
self.saveCmd = $command($scope, save, canExecute);
function save (){
return $timeout( function() {
console.log("save", "yay!");
}, 2000);
}
function canExecute() {
return !self.isBusy;
}
<button class="btn" ng-disabled="!vm.saveCmd.canExecute" ng-click="vm.saveCmd.execute()">