The issue with the AngularJS filter seems to be arising specifically when applied to

My AngularJS filter isn't functioning properly when used with an Object.

Here's the View:

<input type="text" ng-model="searchKeyUser.$" placeholder="Search Keys" class="form-control"><br>
<ul class="list-group">
    <li class="list-group-item clickable keys" ng-repeat="key in keyUsers | filter:searchKeyUser" ng-class="{ active:Group.isActiveKey(key.Key.id)}" ng-click="Group.show()">
          {{key.Key.key}}{{key.show}}
    </li>
</ul>

I've tried using searchKeyUser.$, searchKeyUser.Key.$, searchKeyUser.Key.key, but it didn't work as expected. However, the text {{key.Key.key}}{{key.show}} is displaying correctly.

EDIT: JavaScript code snippet:

(function() {
  var app = angular.module('groupUsers', []);
  app.controller('GroupsController', function($scope, $http){

    //Fetching Relationships Users Keys
    $http.get(myBaseUrl + '/QlikRelKeyUser/returnGroups').success(function(data, status, headers, config) {
      $scope.keyUsers = data;
      console.log($scope.keyUsers);
      for(x in $scope.keyUsers){
        aux = 0;
        qtd = $scope.keyUsers[x].QlikUser.length;
        for(y in $scope.keyUsers[x].QlikUser){
          aux++;
          if(qtd == 1){
            $scope.keyUsers[x].show = ' (' + $scope.keyUsers[x].QlikUser[y].name + ')';
          }else if(aux == qtd){
            $scope.keyUsers[x].show += ', ' + $scope.keyUsers[x].QlikUser[y].name + ')';
          }else{
            if(aux==1){
              $scope.keyUsers[x].show = ' (' + $scope.keyUsers[x].QlikUser[y].name;
            }else{
              $scope.keyUsers[x].show += ', ' +       $scope.keyUsers[x].QlikUser[y].name;
            }
          }
        }
      }
      console.log('');
    }).error(function(data, status, headers, config) {
      console.log('ERROR');
      console.log(config);
    });
    $scope.searchKeyUser = {$:''};
   });

EDIT 2: Same View:

<input type="text" ng-model="searchGroup.$" placeholder="Search Groups" class="form-control"><br>
        <ul class="list-group" >
          <li class="list-group-item clickable" ng-repeat="group in groups | filter:searchGroup" ng-class="{ active:Group.isSet(group.QlikUserGroup.id)}" ng-click="Group.setActive(group.QlikUserGroup.id)">
            {{group.QlikUserGroup.name}}
            <span class='badge bg-important'>1</span>
            <span class='badge' stylee='padding-right:30px;'>{{Group.totalKeys(group.QlikUserGroup.id)}}</span>
          </li>
        </ul>

Using the Same JavaScript:

$http.get(myBaseUrl + '/QlikUserGroup/returnGroups').success(function(data, status, headers, config) {
      $scope.groups = data;
    }).error(function(data, status, headers, config) {
      console.log('ERROR');
      console.log(config);
    });

The output of console.log($scope.groups); shows:

Array[67]
0: Object
$$hashKey: "object:530"
QlikUserGroup: Object
id: "1"
name: "Name name name"
__proto__: Object
__proto__: Object
1: Object
2: Object
3: Object
4: Object
...

Answer №1

Angular filter works only with arrays, but you are trying to pass an object. So there are at least two solutions available:

  • Modify the server-side code to return an array.
  • Create an array from the object in JavaScript, similar to the following:

    $scope.keyUsers = [];
    console.log(data);
    for(x in data){
        var el = data[x];
        $scope.keyUsers.push(el);
        el.show = '('+ el.QlikUser.map(function(el){ return el.name; }).join(', ') +')';
    }
    console.log($scope.keyUsers);
    

var data = {
  '1': {
    'QlikUser': [{
      name: 'a'
    }, {
      name: 'b'
    }, {
      name: 'c'
    }, {
      name: 'd'
    }, ]
  }
}

var keyUsers = [];
console.log(data);
for (x in data) {
  var el = data[x];
  keyUsers.push(el);
  el.show = '(' + el.QlikUser.map(function(el) {
    return el.name;
  }).join(', ') + ')';
}
console.log(keyUsers);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountering issues when implementing react-router with the client-side library

After following the author's suggestion, I've successfully loaded the client-side library. The recommended method is to simply drop a <script> tag in your page and use the UMD/global build hosted on cdnjs. I have ensured that ReactRouter i ...

Error: react/js encountered an unexpected token

While attempting to execute my project, I encountered an error in the console related to a function within the code. The exact error message reads as follows: "63:25 error Parsing error: Unexpected token, expected (function toggleDrawer = (open) => () => ...

JavaScript library designed for efficient asynchronous communication with servers

Looking for a lightweight JS library to handle AJAX cleanly and simplify basic DOM selections on our website (www.rosasecta.com). Currently, we're manually coding a lot of Ajax functionality which is not only ugly but also difficult to manage. We&apos ...

Creating a link using curly braces {{ }} in VUE js

I need assistance in creating links to different pages using data in curly brackets {{ }}, I am having trouble figuring out the correct way to implement them. <div id="app"> <div v-for="data in categorie"> &l ...

Customize the border width and color of a specific column in HighCharts based on dynamic data

I am looking to dynamically change the border width and color of only one column in a basic column chart. Here is an example: var chartingOptions = { chart: { renderTo: 'container', type: 'column' }, xAxis: { categories: [ ...

When utilizing Vue components, the issue of "setattr" arises when trying to assign

Having recently started using Vue.js, I encountered an issue while trying to implement components. Interestingly, the code worked perfectly fine before implementing components. I'm facing an error that is proving to be quite challenging to understand ...

Tips for displaying a sub-menu upon hovering

I am attempting to display the list of sub-menu items when hovering over the main menu item. I have tried using the following CSS code, but it did not work as expected. Any assistance will be greatly appreciated. CSS: summary.header__menu-item.list-menu__ ...

The Javascript calculation function fails to execute proper calculations

I have been facing immense frustration while working on a project lately. The project involves creating a unique Webpage that can calculate the total cost for users based on their selections of radio buttons and check boxes. Assuming that all other functi ...

Prevent links from being clicked multiple times in Rails using Coffeescript

Please make the following link inactive after it has been clicked once <%= link_to "Submit Order", {:action => "charge"}, class: 'btn btn-primary', id: 'confirmButton' %> To permanently deactivate the link, use the code below ...

Unable to modify the background image of a div using jQuery

I'm encountering an issue in my script where I tried to implement an event that changes the background-image of a div when a button is clicked, but it's not functioning as intended. Below is the code snippet: HTML <div class="col-md-2 image ...

What is the best way to retrieve multiple variables using Express.js on Node.js?

Trying to fetch Form data from an HTML page to a Node Js server. The HTML file is named index.html <body> <nav> <ul> <li> <a href="#" class="button add">Add Product</a> <div class="dialog" style="displ ...

Access your Vue.js application using Google Sign-In (GIS)

Having trouble with the discontinuation of gapi.oauth2 by Google and finding the new Sign in With Google tools confusing. Project Structure Looking to implement user sign-in with Google on my Vue frontend and authenticate them using OIDC server flow on ...

Having issues with Firefox rendering JavaScript and CSS correctly

I'm trying to figure out if it's the row class from Bootstrap that's causing issues, or if there's a problem with my JS/CSS not loading properly in Firefox. It seems to be working fine in Chrome and Safari. Any ideas on what could be go ...

Is it possible to set all UI forms to a readonly/disable mode?

We have a specific requirement where, if the user's access level is set to "READ ONLY", all form input elements should be made readonly. Our coding approach involves using a template HTML that contains widgets which are referenced in the correspondin ...

Creating a Test Data List for Selenium functional testing with JAVA

I am currently in the process of setting up test data to validate the text displayed using selenium. I am facing an issue on how to effectively verify content with selenium. Can you offer some suggestions on how to accomplish this and how to structure th ...

From HTML to Python to Serial with WebIOPi

I am facing a dilemma and seeking help. Thank you in advance for any guidance! My project involves mounting a raspberry pi 2 b+ on an RC Crawler rover, utilizing WebIOPi for the task. However, I am encountering challenges and unable to find useful resourc ...

Extracting Data from JSON Using Vue.js

I am facing an issue with extracting data from a JSON file using Vue.js. Below is the HTML and JSON data along with the script. Any help would be appreciated. <!DOCTYPE html> <html> <head> <title>Vu ...

Having trouble processing the Firebase snapshot with Node.js

I have a question regarding a snapshot; ref.orderByChild("index").equalTo(currentIndex).once("value", function(snapshot) {}) After printing the snapshot with ; console.log(snapshot.val()); This is the output that gets printed; {'-LBHEpgffPTQnxWIT ...

User-initiated closure of popup triggers error during Google sign in

After successfully implementing Google signin locally, I encountered an issue when attempting to login on a server. The error message displayed was: 'Uncaught: popup closed by user' Despite disabling adblockers and other potential interference, ...

Error message "Uncaught in promise" is being triggered by the calendar function within the Ionic

Can someone assist me in creating a calendar feature for my app? My concept involves a button with text that, when clicked by the user, opens a calendar. However, I am encountering an error message: ERROR Error: Uncaught (in promise): TypeError: Cannot set ...