Filtering an object based on keys within an ng-repeat loop

I need help with displaying only the items listed in defaults and excluding the others.

<ul ng-controller="Ctrl" class="dropdown-menu">
    <li ng-repeat="(key, value) in Employee.KeyValue | filter:DefaultKeys(key) ">{{key}}</li>
</ul>

angular.module('app', []);

function Ctrl($scope) {
    $scope.DefaultKeys = function(item) {
        var defaultItems = ["SSS No.", "TIN"];

        return defaultItems.indexOf(item);
    };

    $scope.Employee =
        {
            Code: '123',            
            KeyValue:
            {
                'TIN': '9038468',
                'Facebook' : 'https://fb.com/abc'
            }
        }
}

Here is the fiddle for reference.

Any assistance would be greatly appreciated.

Answer №1

Create your own personalized filter.

Custom Filter

angular.module('app', []).filter('MyCustomFilter', function () {
    return function (item) {
        var customKeys = {};
        angular.forEach(['SSS No.', 'TIN'], function (key) {
            if (item[key] !== undefined) {
                customKeys[key] = item[key];
            }
        });
        return customKeys;
    };
});

HTML Implementation

<ul ng-controller="Ctrl" class="dropdown-menu">
    <li ng-repeat="(key,value) in Employee.KeyValue | MyCustomFilter">{{key}}</li>
</ul>

DEMO

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

What is the best way to create a smooth sliding effect using CSS?

Need help with creating a transition effect within a bordered div that reveals hidden content when a button is clicked? I'm looking to have the <a> tag displayed after clicking the button, with both the button and text sliding to the left. Here& ...

Are you looking for a demonstration of "Creative Loading Effects" that triggers when the page is loaded?

I came across this demo for a preloader on my website called Creative Loading Effects, specifically the "3D Bar Bottom" effect, which I find very exciting. However, I noticed that it only loads when we press the button, and not automatically when the page ...

Ways to initiate a flip motion

Looking for a way to create a flip image effect when clicked by the user. Here is the code I have so far: let img = document.querySelector('img') let div; let click = 0; img.onclick=function(){ console.log(click) if(click %2 ==0){ d ...

Issue with initializing MdTable in Vue Material when fetching data

After encountering a null error while trying to fetch remote data to initialize the MdTable component, I shared my issue here. The data is retrieved from a MySQL database as part of a Laravel 5.6 API project. Upon thorough investigation, it seems that the ...

Understanding how to sum the values of two separate dropdown selections using jQuery

Is it possible to combine and total up two different selections to display on the "Total" button below? I have added calculations to each selection. When a user selects a quantity, it should automatically sum up and display on the "Total" button, but I am ...

Draggable slider not functioning properly with linear interpolation

Recently, I've been delving into the world of "linear interpolation" and its application in creating easing effects. However, while the easing functionality of the draggable slider seems to be operational, I'm encountering an issue. The slider re ...

Utilizing JQuery AJAX to Submit a JSONP Form with File Attachments

I have been working on implementing a contact form for our clients who create websites with their own domains through us. As part of our services, we provide hosting and a web editor to help them build their websites. The contact form they include on their ...

Can anyone help me troubleshoot this issue with uploading external JS scripts into my HTML code?

I'm currently facing an issue with my HTML document where the external js file is not loading. Here's a snippet of the HTML: <!DOCTYPE html> <html> <head> <title>...</title> <meta name="viewport" conten ...

Encountering difficulties displaying navigation interface with react native navigation's stack navigator

I am trying to implement a custom side navigation bar in React Navigation without using drawerNavigator. I have fixed the side nav bar and bottom bar in app.js so that they appear on all screens. The main content area should change based on button clicks o ...

Angular 2 does not have the capability to incorporate the Material library

Currently, I am exploring the Microsoft.AspNetCore.SpaTemplates sample of angular 2, where I installed the angular/material npm module in an attempt to integrate input material. UPDATE -- I have a new question about the elimination of server-side renderin ...

Pass JavaScript variables to a PHP file with the help of AJAX

Hey there, I'm new to developing web-based applications and currently learning about AJAX. I've run into a problem while trying to make an AJAX request with user inputs as variables and fetching the same variables in a PHP file. Below is the code ...

Unable to render chart using angularjs-nvd3-directives

After developing a basic Angular - nvd3 project, I decided to utilize liveData.example from the angularjs-nvd3-directives Library on Github. To tailor it for my needs, I made enhancements to integrate with my REST API. Here is the REST API endpoint: http ...

What is the correct method for executing an API request within a div?

I am currently facing a challenge in displaying data in a table sourced from 2 different tables in my database, connected by foreign keys. To retrieve the list of stores, I use the following code snippet: useEffect(()=>{ axios.get("http://localhos ...

Retrieve and manage information from a database using node.js and express

I am currently working on developing a jQuery mobile application and have set up a Linux server with node.js and express. The authentication process seems to be working properly, as well as the connection to another database server. However, I am facing a ...

The dynamic loading of select tag options in Vue.js is not rendering properly

I'm having trouble displaying a select tag with options loaded from a Vue object. However, when I try to render it, something seems off: https://i.sstatic.net/odbC6.png Here is the HTML markup for the select tag: <div class="form-group ui-model" ...

Issue encountered in transmitting information from JSP to servlet

I am facing an issue with receiving data from JSP to servlet. I understand that I need to serialize this data using JSON. In my JSP, I have written the following JavaScript code: var myJSONText = JSON.stringify(items); document.getElementById('test&a ...

"Troubleshooting a blank page issue in Angular UI Router caused by query string

I've been struggling with an issue related to query string parameters for quite some time. When I navigate to /, everything works perfectly fine. However, if I try something like /?anything, it simply doesn't work. These are the configurations in ...

Issues with javascript functionality in Internet Explorer version 9 and higher

Currently, there is a flash music player (audioplay) embedded on a website. Despite personal preferences against having music on websites, it was requested by the client. The functionality in question involves using JavaScript to trigger "stop" and "play," ...

Various ways to utilize Apollo's Query property

There are a couple of ways I've come across to utilize the new Query and Mutation props from Apollo. However, I've only been able to successfully implement one of them. First, defining the query within the Query prop directly like this: <Qu ...

Create a new array by dynamically generating a key while comparing two existing arrays

One of the features in my app involves retrieving data from an API and storing it in $scope.newz. The previous user activity is loaded from LocalStorage as bookmarkData. I am facing a challenge with comparing the contentId values in arrays $scope.newz an ...