Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8577567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:11:20+00:00 2026-06-11T20:11:20+00:00

I have ng-repeat ed data, and am trying to get only the ones the

  • 0

I have ng-repeated data, and am trying to get only the ones the user has selected. I’m not sure how to do it though, this is what I have:

HTML:

<div data-ng-controller="MyCtrl">
    <ul>
        <li data-ng-repeat="record in records">
            <input type="checkbox" ng-model="record.Id"> {{record.Id}}
        </li>
    </ul>
    <a href="javascript:;" data-ng-click="ShowSelected()">Show Selected</a>
</div>

JS:

function MyCtrl($scope) 
{
    $scope.records = [ { "Id": 1 }, { "Id": 2 }, { "Id": 3 } ];
    $scope.ShowSelected = function() 
    {
        // how can I get only the selected records here ?
    }
}

I did get it working one way – by adding a isSelected:false property to each object and changing the ng-model of the checkbox to record.isSelected, I can then filter on that in the ShowSelected function. This seems inefficient though, I don’t want to be adding extra properties to the model if can avoid it.

Is there a better way ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:11:21+00:00Added an answer on June 11, 2026 at 8:11 pm

    JavaScript

    var app = angular.module('plunker', ['ui']);
    
    app.controller('MyCtrl', function($scope) {
        $scope.records = [ { "Id": 1 }, { "Id": 2 }, { "Id": 3 } ];
        $scope.selected = {};
        $scope.ShowSelected = function() {
          $scope.records = $.grep($scope.records, function( record ) {
            return $scope.selected[ record.Id ];
          });
        };      
    });
    

    HTML

    <div data-ng-controller="MyCtrl">
        <ul>
            <li data-ng-repeat="record in records">
                <input type="checkbox" ng-model="selected[record.Id]"> {{record.Id}}
            </li>
        </ul>
        <a href="javascript:;" data-ng-click="ShowSelected()">Show Selected</a>
    </div>
    

    http://plnkr.co/edit/lqtDQ6

    You can store the flag in separately and use it to filter the data.

    updated plunk as some CDN links were broken.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in my application, i'm trying to achieve something like this: i have: data 0,
I have this small exercise that I am trying to finish, but I get
I have been messing with this for too long trying to get it to
I have this in my CSS file: body {style.css (line 3) background:#CDF8FF url(images/final_bg.jpg) no-repeat
I'm trying to sort data by different fields ascending and descending. But I have
Im trying to import json data to mysql.My json file nearly 3.7Mb and have
i have been trying to learn PHP Repeat Region... i have searched google but
I wrote the following loop since I have to repeat the same/similar code 25
I have created a repeat control that list some documents. I would like to
I have a simple 'repeat with' in an AppleScript, and would like to move

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.