Filtering with Angular

I have a form that is structured into different sections as shown below:

education: {faculty: "", high_school: ""}
experience: {experience_1: "", experience_2: "", experience_3: ""}
personalInfo: {id: "", type: "", email: "", password: "", password_new: "", first_name: "", last_name: "",…}
skills: {skill_1: "", skill_2: ""}

All inputs are generated using ngRepeat directive.

<div ng-repeat="(key, val) in user" >
    <div ng-repeat="(k,v) in val | filter:filterBySection" class="formParameter" >

        <span class="param_label">
            {{k}}:
        </span>

     <span e-class="form-control " class="formParameterValue" editable-text="user.{{key}}.{{k}}" e-name="{{k}}">{{v}}</span>
    </div>   
</div>

My question is how can I create a filter to display only the selected section. For instance, if I click on the education button, it should only show 'faculty' and 'high school'

<li ng-repeat="(a,b) in user" ng-click="filterBySection = ?:{{a}}" ng-model="filterBySection"><a href="#">{{doc_param}}</a></li>

Your suggestions on implementing this feature would be greatly appreciated.

Answer №1

If you want to display different div containers based on a variable set by a button click event, you can achieve this using the "tab" variable in AngularJS. By assigning different values to "tab" upon button clicks, you can control which div is shown by using ng-show to check the value of "tab".

// Sample links or buttons
<a href ng-click="tab = 1"> Description</a>
<a href ng-click="tab = 2"> Specifications</a>

// Corresponding DIVs
<div class ="panel" ng-show="tab === 1">
   <h4>Description</h4>
   <p>{{product.description}}</p>
</div>
<div class ="panel" ng-show="tab === 2">
   <h4>Specifications</h4>
   <p>{{product.specification}}</p>
</div>

Answer №2

To enhance the functionality of filtering, it is recommended to develop a personalized filter instead of relying on the standard module. This custom filter can evaluate whether an item should be displayed based on specific criteria, utilizing the ng-show directive.

Maintain the association between your list items and the filterBySection model as you have been doing with the <li> elements.

Revamp the structure of the div containing the ng-repeat statement similar to this:

<div ng-repeat="(key,value) in data" ng-show="key | customFilter:filterBySection" class="customElement" >

Incorporate a custom filter within your AngularJS application by extending the angular.module object with a new filter function:

var app = angular.module("app", []);
app.filter('customFilter', function ($filter) {
    return function (input, section) {
        // Implement conditional statements such as
        if (section == 'Category' && (input == 'category1' || input == 'category2'))
        { return true; }
        // Add more conditions here...
    };
});

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

The functionality to display dynamic images in Vue.js appears to be malfunctioning

As a newcomer to vue.js, I am facing a challenge in dynamically displaying images. Manually changing the images works fine, but I'm running into issues with dynamic display. I've come across similar problems online, but none of the solutions seem ...

The jQuery plugin fails to display properly when used in conjunction with AngularJS

Currently, I am working on a tabs application and have implemented an angularJS directive to utilize the jquery tabs plugin. Unfortunately, I am facing issues with the view not updating properly and the tabs not being displayed as expected. Here is a link ...

Save various checkbox options to firebase

Utilizing Angularfire, my goal is to save data using multiple checkboxes. HTML <form role="form" ng-submit="addTask(task)"> <label class="checkbox-inline" ng-repeat="(key, value) in students"> <input type="checkbox" id="{{key}}" valu ...

Is there a way to have dynamic content from angularJS show up in an iframe?

When working with tabular content generated using ng-repeat in AngularJS, it is important to find a way to display this content within an iframe. The goal is to allow users to drag and resize the content as needed. However, using the iframe src attribute ...

Tips on making a fresh form appear during the registration process

After clicking on a submit button labeled as "continue" within a form, a new form will appear for you to complete in order to continue the registration process. ...

The dynamic text feature in my Angular Material gridlist functions perfectly in CodePen, however, it fails to work when

I have enhanced the Angular material gridlist demo by incorporating static and dynamic texts into the grid tiles. While this modification works flawlessly on Codepen (see my provided link), it does not function properly when deployed on my server. The sta ...

Tips for assigning an AngularJS data-bound value to the href attribute of an anchor tag

I need to include multiple email ids separated by commas from an angularjs binded value in the mailto field of an anchor tag. The team.emails variable can contain either a single email id or multiple email ids separated by commas. <tr ng-repeat="team ...

Exploring AngularJS capabilities: Retrieving data and headers from an HttpResponse

Currently, I have a REST API developed using Spring Boot. In the frontend, AngularJS 1.5 is being used. The login service not only sends data but also includes a header. I am wondering how I can effectively read both the data and header on the AngularJS ...

Removing an element from an array of objects using React

I am currently fetching data from a JSON file and using the map method to display it while storing it in a state. The goal is to delete an item when the delete button is clicked, so I am utilizing the filter method for this. However, I encountered an error ...

The beforeunload event only triggers when the page is refreshed, not when the page is exited

I am currently utilizing the react-admin framework (version 3.2) and I am attempting to trigger the beforeunload event when a user is moving away from the Edit form view. For instance, if my pathname is "feed/123", I want the beforeunload event t ...

Steps to obtain the original video file from a Google Drive link for embedding on a website

I have a video stored on Google Drive with a link that is supposed to provide the raw video file. However, when I click on the link, I am directed to an image instead. https://drive.google.com/uc?id=xxx How can I obtain the correct playable link to use th ...

Challenges with 'this' reference in a requireif causing Vuelidate complications

     Need help with vuejs component using vuelidate and validations:     validations: {      invoice: {          dueDate: {              required,          },          tax: {              require ...

Interactive Show Map with Autocompletion Feature

I attempted to implement autocompletion for my application and integrate it with Google Maps, but I'm encountering issues. The code for autocompletion is located in a separate JavaScript file called autocomplete.js. Since I already have a Google Map ...

Swapping out a section of text with AngularJs

Can you provide guidance on how to replace a string in AngularJs? I would like to achieve the following: {{string.replace('some', 'thing')}} Appreciate any help! ...

Verify if two arrays of objects demonstrate unique distinctions within the latter

My task involves working with two arrays of objects, each containing a unique property id that corresponds to a filterID retrieved from a dynamoDb database. The goal is to extract the objects that have different values associated with the same id. const fi ...

Tips for displaying AJAX response data on a webpage

I am currently developing a Spring Boot application that includes a website with a submenu featuring various computer games. My goal is to have the server respond by sending an image (specifically a path to the image) of the selected game when a position i ...

What is the best way to replicate the functionality of AngularJS decorators in pure vanilla JavaScript (ES6)?

Using AngularJs Decorators offers a convenient method to enhance functions in services without altering the original service. How can a similar approach be implemented with javascript classes? In my current project, I have two libraries - one containing g ...

What steps should I take to implement user access control in my current AngularJS application?

I have developed a login authentication application using AngularJS, but now I want to transform it into a user access control app. Can anyone provide suggestions on how to achieve this? Any help in guiding me through the process of enhancing my app would ...

I encountered an error while attempting to lint my code because ESLint was not configured to ignore the

Trying to set up eslint in a Next.js project, here is the file structure: .eslintignore .eslintrc.js .next .prettierrc .stylelintrc.js components forms modals modules node_modules In my .eslintignore file, I have added node_modules/*. When running eslint ...

Challenge encountered while using the like operator with Integer data type in Mongoose

I am encountering an issue with constructing a where query in Mongoose for an integer data type. The key 'facevalue' is of integer data type. When I execute a find query, it appears something like this: Below is the code snippet: var orCond ...