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

  • SEARCH
  • Home
  • 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 8395945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:25:20+00:00 2026-06-09T20:25:20+00:00

Say I have a controller in an AngularJS web app which has a data

  • 0

Say I have a controller in an AngularJS web app which has a data array that stores objects which are very similar but require a different template depending a member variable ‘type’. For example :

function fooCtrl($scope) {
    $scope.bar = [
        {"name": "example 1",
         "type": "egType1",
         "text": "Some example text"},
        {"name": "example 2",
         "type": "egType2",
         "text": "Some example text"},
        {"name": "example 3",
         "type": "egType3",
         "text": "Some example text"},
    ];
}

One could easily create a template to output the data using the ng-repeat directive as follows :

<ul>
    <li ng-repeat="item in bar">
        {{item.name}}
        <p>{{item.text}}</p>
    </li>
</ul>

However this will result in each item having the same display.

What is the best method to output all the items in bar while being able to vary the template depending on the value of item.type?

  • 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-09T20:25:21+00:00Added an answer on June 9, 2026 at 8:25 pm

    I suppose you can use ngSwitch directive, with something like this:

    <li ng-repeat="item in bar">
        <div ng-switch on="item.type">
            <div ng-switch-when="egType1">
                {{item.name}}
                <p>{{item.text}}</p>
            </div>
            <div ng-switch-when="egType2">
                XXX {{item.name}}
                <span>{{item.text}}</spab>
            </div>
            <div ng-switch-default>
                DEFAULT {{item.name}}
                <span>{{item.text}}</spab>
            </div>
        </div>
    </li>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say if I have a controller, profile, which has just two actions. The first
Say I have a class ObjectA (a view controller for example), that does this
Let say I have two methods in MVC 4 Web API controller: public IQueryable<A>
I have a navigation-based app and say my root controller A causes a viewController
Lets say I have a controller class A which implements UIImagePickerControllerDelegate. within A ,
Lets say you have an array that is rendered in a ul with an
Lets say I have a controller which provides search functions for a student: public
Say that you have a controller named Buildings and that every user in the
Say I have a controller that returns a list of users. The users are
Let's say I have a Controller that handles a CRUD scenario for a 'Home'.

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.