1

I am new to angular and programming and need some guidance and help learning. I have an html page that has 5 tabs, "Who", "What", "Where", "When", and "Events". I have the following code. How do I take the json category entries in my controller and separate them into the html tab that relates to it? I appreciate any help.

//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"}
    ]

I know that I need to iterate through the json, so I wrote this

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

};

4
  • The html didn't post correctly. Here it is again: Commented Dec 2, 2013 at 16:26
  • Nevermind, I was able to edit...I am definitely a NOOB right out of school. I appreciate any opportunity to learn!! Commented Dec 2, 2013 at 16:33
  • fiddles are are an easy way for us to help... hint hint. Commented Dec 2, 2013 at 16:34
  • 1
    I will use fiddle in the future. Thank you for the tip :-) Commented Dec 3, 2013 at 15:11

1 Answer 1

1

A simple way. For each category do the below. Add a filter and it will automatically do it for you.

ng-repeat="chart in charts|filter:{category: 'Where'}"
Sign up to request clarification or add additional context in comments.

4 Comments

How would I do the same thing in jquery?
I created the tab menu using jquery. Here is my fiddle link jsfiddle.net/cg085b/35NJc I have tried to use the ng-repeat="chart in charts|filter:{category: 'Where'}" loop with this to get the charts in the correct tab, but it doesn't work. How would I get the charts to filter in to the correct tab?
So... I dont see any angular code here ... :) If you give me a more organized question I can probably help.
lol...I switched to jquery. My boss kept changing his mind. I was able to make a custom nav tab menu. Thank you for all of your help!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.