Reputation: 221
Each radio button has one value. I want to add the values every time someone select a radio button. To select the right radio button 1 will be added and for wrong 0.5 will be subtracted. The final result will show in ov div.
var app = angular.module('plunker', []);
app.controller('aCtrl', function($scope) {
var v= 0 ;
$scope.cal = function(){
$scope.rv.click();
v +=$scope.rv;
$scope.ov = JSON.stringify(v);
};
});
Here is my plunker link http://plnkr.co/edit/onjtGkkG0FiK4dOCmJfX?p=preview
Upvotes: 0
Views: 57
Reputation: 293
This is simple directive for your purpose:
var app = angular.module('plunker', []);
app.controller('aCtrl', function($scope) {
$scope.v = 0;
});
app.directive('addOnCheck', function () {
return {
restrict: 'A',
scope: {
addOnCheck: '='
},
link: function (scope, el, attrs) {
el.on('click', function () {
scope.$apply(function () {
scope.addOnCheck += attrs.value;
});
});
}
};
});
Here is plunker http://plnkr.co/edit/6vz5VXnnub5KgFxtXUAg?p=preview
Upvotes: 1