Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8384879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:31:24+00:00 2026-06-09T17:31:24+00:00

I’m trying to create a custom controller that shows a bunch of similar objects

  • 0

I’m trying to create a custom controller that shows a bunch of similar objects that are bound to a data set like the following:

[{name: card1, values: {opt1: 9, opt2: 10}},{name: card1, values: {opt1: 9, opt2: 10}}]

I’d like to show the name and one of the values for-each card (represented as a square for each on the screen), with only one value shown depending on whether the user clicks on a button for option 1 or option 2. I’m stuck on how to change the value shown when using an ng-repeat.

html code:

<div ng-controller="aggViewport" >
<div class="btn-group">
    <button class="btn active">opt1</button>
    <button class="btn">opt2</button>
</div>
<div id="container" iso-grid width="500px" height="500px">
    <div ng-repeat="card in cards" class="item {{card.class}}">
        <table width="100%">
            <tr>
                <td align="center">
                    <h4>{{card.name}}</h4>
                </td>
            </tr>
            <tr>
                <td align="center"><h2>{{card.opt1}}</h2></td>
            </tr>
        </table>        
    </div>
</div>

controller:

module.controller('aggViewport',['$scope','$location',function($scope,$location){
$scope.cards = [{name: card1, values: {opt1: 9, opt2: 10}},{name: card1, values: {opt1: 9, opt2: 10}}];


}]);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:31:26+00:00Added an answer on June 9, 2026 at 5:31 pm

    Here is a possible solution to your problem

    <div ng-controller="aggViewport" >
    <div class="btn-group" >
        <button ng-click="setOption(opt.name)" ng-repeat="opt in optList" class="btn active">{{opt.name}}</button>
    </div>
    <div id="container" iso-grid width="500px" height="500px">
        <div ng-repeat="card in cards" class="item {{card.class}}" ng-controller="aggCardController">
            <table width="100%">
                <tr>
                    <td align="center">
                        <h4>{{card.name}}</h4>
                    </td>
                </tr>
                <tr>
                    <td align="center"><h2>{{getOption()}}</h2></td>
                </tr>
            </table>        
        </div>
    </div>
    

    And in your controller :

    module.controller('aggViewport',['$scope','$location',function($scope,$location){
    $scope.cards = [{name: card1, values: {opt1: 9, opt2: 10}},{name: card1, values: {opt1: 9, opt2: 10}}];
    
    $scope.option = "opt1";
    
    $scope.setOption = function(val){
    $scope.option = val;
    }
    
    }]);
    
    module.controller('aggCardController',['$scope',function($scope){
    
    $scope.getOption = function(){
    return $scope.card.values[$scope.option];
    }
    
    }]);
    

    Just to explain what is happening here. THe aggCardController is defined separately because a new scope is created when you use a ng-repeat. Also, when you introduce a controller with an ng-repeat you create the controller which will control that scope. So now you can access each scope individually. And a new controller will be created for each of the scopes created. Since in the html, the aggCardController comes inside of the aggViewPort it will inherit properties from the parent scope. So if you declare option in aggViewPort it will get inherited into all the child scopes.

    The reason for introducing this new controller here is because of this statement

    return $scope.card.values[$scope.option];
    

    Since we are trying to access $scope.card here and remember that card is a new variable created in the repeater. This new variable is only available in the child scopes created by the repeater. If you did not need to access $scope.card then we could have as well written this getOption() function in the parent scope.

    Also note that all objects in javascript are assciative arrays. This is the reason why we are using the array access operator [] to access the value in opt1 or opt2.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.