Skip to content

Instantly share code, notes, and snippets.

@telagraphic
Created January 21, 2014 02:10
Show Gist options
  • Save telagraphic/8533245 to your computer and use it in GitHub Desktop.
Save telagraphic/8533245 to your computer and use it in GitHub Desktop.
angular.module('myApp.directives', [])
.directive('checkboxLimit', function() {
return {
restrict: 'A',
replace: true,
link: function(scope, ele, attrs, ctrl) {
console.log(ele);
scope.inputDisabled = false;
scope.$watch('bet.winner', function(newVal, oldVal) {
var bets = angular.element(document.getElementsByClassName('currentBet'));
//console.log(bets);
if (newVal === true) {
angular.forEach(bets, function(bet) {
if (bet.hasClass('toHide'))
bet.addClass('toHide');
});
} else if (newVal === false) {
angular.forEach(bets, function(bet) {
if (!bet.hasClass('toHide')) {
bet.addClass('toShow');
}
});
}
});
}
}
});
<div ng-controller="BettingController">
<h2>Todays Bets</h2>
<ul id="todayBets">
<li ng-repeat="bet in bets | orderBy:'startTime' | orderByPriority | getCurrentBets">
<h2>{{bet.better}}</h2>
<span>{{bet.startTime}}</span>
<b>{{bet.timeLength}}</b>
<input type="checkbox" ng-model="bet.winner" ng-change="updateWinner(bet);" class="currentBet" checkbox-limit>
</li>
</ul>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment