Cookies on this site

We would like to use cookies to understand how the site is used and to measure our campaigns. Nothing is set until you choose, and you can change your mind at any time from “Cookie settings” at the foot of every page. Privacy policy

Contact UsContact Us

Resources / Blogs

Cloud & apps

AngularJS – ng-repeat and Radio Buttons

AngularJS - ng-repeat and Radio Buttons: I recently had this problem where I had to select an item from a table. Nothing much, but I would like to share how I avoided it.

· · 1 min read

AngularJS

I recently had this problem where I had to select an item from a table. Nothing much, but I avoided buttons for this task and instead used a radio button against each row:

where
$scope.users = [{“userId”: 1, “firstName”: “a”,“lastName”:“b”},
{“userId”: 2, “firstName”: “c”,“lastName”:“d”},
{“userId”: 3, “firstName”: “e”,“lastName”:“f”}];
and
$scope.toggleSelection = function (index) {
$scope.selectedUsers = $scope.users[index];
};

I used $scope.selectedUsers to retain the selected object. In operation this worked fine in the context that whatever item was selected last would be retained except that on clicking one radio button after another the previous radio button was not getting cleared. The problem here being that ng-repeat creates a new child scope from the parent scope of the table for each new row. I searched around and came across instances that pointed that I need to be using $parent.user as my ngModel instead of just user. Instead of resorting to such deliberate methods, here is what I did:

In the controller, I added a new attribute to each item in the users array:

for(var i = 0; i < $scope.users.length; i++){
$scope.users[i].selectedValue = false;
}

and in the toggleSelection function, I reset the selectedValue again:

$scope.toggleSelection = function (index) {
$scope.selectedUsers = $scope.users[index];
for(var i = 0; i < $scope.users.length; i++){
$scope.users[i].selectedValue = false;
}
};

In the DOM:

And now all the radio buttons are cleared on clicking by the ng-value attribute in the DOM but as soon as the click event is completed ng-dirty class is automatically applied to the radio button on which the click was applied and this fills the selected radio button.

← All articles

Case studies

Cloud Consulting in practice

Client names are withheld. We are happy to share details on a call.

All case studies
  • Delivered

    On-prem → Amazon RDS

    Nonprofit

    Cloud Consulting

    Oracle from on-premises to Amazon RDS for a national nonprofit

    The nonprofit's on-premises Oracle database had become hard to maintain and scale. We planned the move with automated workflows and validation tests, migrated to Amazon RDS for Oracle with minimal disruption and left a repeatable process for future changes.

    • Automated, tested migration
    • Less day-to-day database upkeep
  • Delivered

    600k files, < 3 days

    Document management

    Microsoft

    600,000 documents moved from ImageRight to SharePoint in under three days

    A one-file-at-a-time script would have needed about 22 days of continuous running. We rebuilt the migration around a SQL work queue with parallel uploads, automatic retries and crash recovery, and it finished unattended in under three days.

    • 1,125 → 8,314 files per hour
    • Under 3 days instead of about 22
  • Delivered

    Every change, flagged

    Food manufacturing

    AI Consulting

    Label comparison agent for a national food cooperative

    Compares two versions of a product label, highlights every change, annotates the PDF and returns an audit-ready list of differences. We moved it from Copilot Studio to Azure Functions when the document processing outgrew the low-code platform.

    • Audit-ready differences in one chat turn
    • Rebuilt from low-code to cloud functions

Keep reading

All Cloud & apps articles

Moving an application to the cloud?

Request a migration plan consult. We will scope the move with you and come back with a fixed-scope plan.