Organizing into distinct categories using Angular

I'm a beginner in the world of Angular and programming, seeking guidance on how to learn. I have an HTML page with 5 tabs: "Who," "What," "Where," "When," and "Events." The code snippet below showcases my current setup. Can anyone provide assistance on how to efficiently organize the JSON category entries within my controller and align them with their respective HTML tabs? Any help would be greatly appreciated.

//html
<div id="chartsContainer" class="row">
    <div class="col-xs-12">

            <div id="" class="row">
                <h3 class="pull-left" style="color:white">CHARTS</h3>
                <form ng-submit="filterCharts()" class="pull-right">
                    <!-- Single button -->
                    <div class="btn-group">
                      <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                        all <span class="caret"></span>
                      </button>
                      <ul class="dropdown-menu" role="menu">
                        <li><a href="#">Used</a></li>
                        <li><a href="#">Unused</a></li>
                      </ul>
                    </div>
                </form>
            </div>

            <div id="tabMasterContainer" ng-controller="TabsDemoCtrl">

                <tabset vertical="false" type="navType">
                <tab heading="Who">
                <a ng-click="groupBy( 'category' )">Category</a>
                        <div id="chartsList" class="row">

                            <div id="" class="col-md-3" style="background-color:blue; height:100px; margin: 10px;" ng-repeat="chart in charts">

                                <p><i class="fa {{chart.icon}} fa-2x" style="color:white"></i></p>
                                <p style="color:white"> {{chart.description}} </p>
                            </div>
                        </div>

                </tab>
                <tab heading="What">
                    <div id="tabContainer">
                    <div id="" class="col-md-3" style="background-color:blue; height:100px; margin: 10px;" ng-repeat="chart in charts">
                                <p><i class="fa {{chart.icon}} fa-2x" style="color:white"></i></p>
                                <p style="color:white"> {{chart.description}} </p>
                            </div>
                    </div>
                </tab>
                <tab heading="When">
                    <div id="tabContainer">
               <div id="" class="col-md-3" style="background-color:blue; height:100px; margin: 10px;" ng-repeat="chart in charts">
                                <p><i class="fa {{chart.icon}} fa-2x" style="color:white"></i></p>
                                <p style="color:white"> {{chart.description}} </p>
                            </div>
                    </div>                  
                </tab>
                <tab heading="Where">
                    <div id="tabContainer">
                <div id="" class="col-md-3" style="background-color:blue; height:100px; margin: 10px;" ng-repeat="chart in charts">
                                <p><i class="fa {{chart.icon}} fa-2x" style="color:white"></i></p>
                                <p style="color:white"> {{chart.description}} </p>
                            </div>
                    </div>
                </tab>
                <tab heading="Events">
                    <div id="tabContainer">
                <div id="" class="col-md-3" style="background-color:blue; height:100px; margin: 10px;" ng-repeat="chart in charts">
                                <p><i class="fa {{chart.icon}} fa-2x" style="color:white"></i></p>
                                <p style="color:white"> {{chart.description}} </p>
                            </div>
                    </div>
                </tab>

              </tabset>
            </div>


    </div>
  </div>




$scope.charts = [
        { id : 1, description: "Date Range", icon : "fa-camera-retro",         category : "When"},

        { id : 2, description: "Time of Day", icon : "fa-cog", category :     "When"},
        { id : 3, description: "Day of Week", icon : "fa-bar-chart-o", category : "When"},
        { id : 4, description: "Age Range", icon : "fa-wrench", category : "Who"},
        { id : 5, description: "who foo", icon : "fa-wrench", category : "Who"},
        { id : 6, description: "what foo", icon : "fa-wrench", category : "What"},
        { id : 7, description: "what foo", icon : "fa-wrench", category : "What"},
        { id : 8, description: "where foo", icon : "fa-wrench", category : "Where"},
        { id : 9, description: "where foo", icon : "fa-wrench", category : "Where"},
        { id : 10, description: "basketball foo", icon : "fa-wrench", category : "Events"},
        { id : 11, description: "Doctor Who Foo", icon : "fa-wrench", category : "Events"},
        { id : 12, description: "You foo", icon : "fa-wrench", category : "Who"},
        { id : 13, description: "Boo foo", icon : "fa-wrench", category : "Events"},
        { id : 14, description: "da bar", icon : "fa-rocket", category : "Where"}
    ]

To process the JSON data effectively, I created this iteration function:

function chartFinder(chartArray, id){
for (var i = 0; i < chartArray.length; ++i) {
    if(id==chartArray[i].key)
       return id[i].value;
}

};

Answer №1

A straightforward method. Take the following steps for each category. Apply a filter, and it will handle the task automatically.

ng-repeat="chart in charts|filter:{category: 'Where'}"

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

Navigating through elements within underscore.js templates

Can someone please help me out? I'm finding this task more difficult than it should be, so I must be overlooking something simple... I am working with a variable that is acting as an underscore template. Here is an example of the code snippet: var t ...

Is there a way to speed up the loading time of React in the browser?

My experience with using React in the browser has been positive, but I'm facing a speed issue. The initial loading time is quite lengthy as it compiles. I am looking for a way to use React/JSX directly in the browser and have it compile instantly wit ...

JSON object name

Here are the specific file locations for loading each of the CSS and JS files. <link href="css/default.css" rel="stylesheet" /> <script src="js/main.js"></script> In XML, the filename is input as shown below ...

What is the best way to execute AJAX requests in a loop synchronously while ensuring that each request is completed

I am looking to implement an AJAX loop where each call must finish before moving on to the next iteration. for (var i = 1; i < songs.length; i++) { getJson('get_song/' + i).done(function(e) { var song = JSON.parse(e); addSongToPlayl ...

Is Angularjs revolutionizing the use of service dictionaries for Dependency Injection by consolidating multiple services into one?

Despite using ng-annotate, the process of declaring and updating dependencies arrays, along with dependency injection params, is becoming tedious for me. This is especially evident in my controllers and directives. I'm wondering if it would be feasib ...

Accessing the value of a hidden field within an ng-repeat loop when binding to an HTML table

I am working on a project where I have an HTML table with data being bound from AngularJS. The structure looks something like this: <tr ng-repeat="item in List| filter: { MachineType: 'Physical' }"> <td>{{item.MachineType}}< ...

Angular view showcasing a JSON array

After retrieving data from the Laravel API, I used the following method: this.dataService.getData().subscribe(res=>{ this.contacts=res }); Upon receiving a JSON array response from Laravel like the one below, I attempted to iterate throu ...

Using browser's local storage: deleting an entry

I recently came across a straightforward to-do list. Although the inputs are properly stored in local storage, I encountered issues with the "removing item" functionality in JS. Even after removing items from the HTML, they still persist in local storage u ...

Is there a way to restore a previous version of package-lock.json?

Currently, I am facing the challenge of adjusting a JS/node project that includes a package.json but lacks a committed package-lock.json file. Additionally, the original package-lock.json from the author is not available as newer versions have been develop ...

Child functional component does not refresh after its props are altered by its parent component

Looking at the following code: MainParentComponent.js let data = 0; function MainParentComponent() { function handleClick() { data++; } return (<> <button onClick={handleClick}>Increase</button> < ...

Discover the chosen image displayed within an ng-repeat showcased in a separate container

I am facing an issue with a table that uses ng-repeat to display data. One of the columns contains photos. When I edit a specific entry in the table, I want the corresponding photo to be shown. How can I achieve this? The code for my table looks like this ...

Selected value is not displayed in the textbox when using autocomplete feature

---Ajax---- An issue has arisen with the autocomplete feature. While typing "wi" (for example, wipro), the drop-down list appears as expected. However, if only "wi" is selected in the text box, $(document).ready(function () { $("#company_name").key ...

Exploring the intricacies of password reset functionality in Node.js and Angular

I am currently exploring the implementation of password reset and forgot password features using AngularJS (1.x) with Nodejs as the backend. After coming across this informative article on Nodejs backend setup, I stumbled upon a relevant discussion on Angu ...

Modify jQuery to update the background image of a data attribute when hovering over it

Something seems to be off with this topic. I am attempting to hover over a link and change the background image of a div element. The goal is to always display a different picture based on what is set in the data-rhomboid-img attribute. <div id="img- ...

Determining When to Activate Button Based on Angular - Verifying That All Choices Have Been Ch

This quiz application requires the user to choose options before proceeding to the next page, with the next button being disabled by default. Once all options are chosen, the next button should become enabled. NOTE: Although the functionality for selecti ...

Issue with React Material UI: Snackbar is closing when Dialog closes which is not the intended behavior

When using Material UI dialog, it unexpectedly closes the snackbar as well. To illustrate this strange issue, I have prepared a demonstration: https://codesandbox.io/s/react-hooks-counter-demo-v20w3 I am passing states from the parent component to the c ...

Can Next.js 13 components maximize performance by utilizing server and client components simultaneously? What is the best approach to achieve this?

Introduction Currently, I am exploring server and client components in Next.js 13 and looking to incorporate them into my project. One of the key features is a container component that utilizes react-intersection-observer to track which section is visible ...

Having trouble posting data in node.js using MongoDB and EJS

Hey everyone, I'm currently working on creating a page with a form and text input fields. However, I'm encountering an error that says "Cannot Post". Here is my code, any help would be greatly appreciated. Why isn't it working? This is app. ...

Unable to open file downloaded from Laravel with Vue.js support

I am facing an issue with my function in Laravel and vue.js. Even though it successfully downloads the desired file, when I try to open it, I consistently receive an error message stating that the file type is unsupported. Below is the vue.js function I a ...

Trouble with Mongoose adding items to an array

ReviewSchema with Mongoose: import mongoose from "mongoose"; const ReviewSchema = new mongoose.Schema({ likes: { type: Number, required: true, default: 0, }, reactedBy: [ { required: true, ...