If you need assistance with converting some code to follow Angular conventions, I can help.
- Instead of using
document.getElementsByClassName
, try using angular.element
(which is provided by jQLite to retrieve elements)
- You may utilize
$filter
when checking if an attribute is checked or not
CODE
self.isButtonEnabled = function() {
var selectLineCheckboxs = angular.element('.selectLineRadioInput');
var checkedValues = $filter('filter')(selectLineCheckboxs, { 'checked': true }); // perform filtering and check for values
self.selectLineChecked = checkedValues.length > 0 ? true : false;
return self.selectLineChecked;
};
Note: Ensure that you include the dependency for $filter
in your controller before utilizing it
Update
I recommend creating a custom filter that can be used for various purposes, such as dynamically checking if a property value is true or not. While your existing code is similar to what you requested, I have refactored it into a reusable component that can work dynamically for any property value check.
Filter
.filter('isPropertyTrue', function () {
return function (elements, property) {
var returnArray = [];
angular.forEach(elements, function (val, index) {
if (val[property]) returnArray.push(val)
});
return returnArray;
}
});
Code
$scope.isButtonEnabled = function () {
var selectLineCheckboxs = document.getElementsByClassName('selectLineRadioInput');
var checkedValues = $filter('isPropertyTrue')(selectLineCheckboxs, 'checked');
self.selectLineChecked = checkedValues.length > 0 ? true : false;
return self.selectLineChecked;
};
JSFiddle
I hope this information proves helpful to you. Thank you.