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 8660925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:22:44+00:00 2026-06-12T16:22:44+00:00

Let’s say we have a person object with a few person-properties personModel = {

  • 0

Let’s say we have a person object with a few “person-properties”

personModel = {
 membership-number : "abcd",
 name : "Anonymous",
 dob : "14/04/2009",
 avatar : "image.png"
}

Let’s also say we have metadata about these “person-properties”.

meta-data = {
 membership-number: {data-type : "string", editable : "false"},
 name : {data-type : "string", editable : "true"},
 dob : {data-type : "date", editable : "true"},
 avatar : {data-type : "image", editable : "true"}
}

Now I would like to list these properties of the personModel on a page with the following constraints.
member-ship name which is string and non-editable, should be displayed as a label.
All editable strings as text box, all date types with a date-picker, etc.

I know this can be done with angular directives. Have a directive called person which will iterate through the “person-properties” of the personObject.

<person ng-model={{personModel}}> </person>

and have a directive for each “person-property” inside the person, like :

<person-property ng-repeat = {{prop in person-properties}}> </person-property>

Let’s also assume that the property directive has access to the metadata.
To get templates based on the property-type, I can write if-else in the person-property’s definition to choose which template to return, like this skeleton.

if(property_type === "date"){
   template = "<datepicker> </datepicker>"
}
else if (property-type === "numeric"){
   template = "<numeric-editable-box> </numeric-editable-box>"
}

But is there a more elegant way to do this?

WPF has something called TemplateSelector to do this. Does angular have something similar that I am unaware of?

  • 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-12T16:22:45+00:00Added an answer on June 12, 2026 at 4:22 pm

    I think that ng-switch may fit your needs.
    switch on the meta data and display appropriate elements.

    <div ng-switch="property_type">
      <datepicker when="date"></datepicker>
      <numeric-editable-box when="numeric"></numeric-editable-box>
    </div>
    

    etc…

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

Sidebar

Related Questions

Let's say I create an object like this: Person: NSString *name; NSString *phone; NSString
Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do
Let's say I have the following data frame: > myvec name order_no 1 Amy
Let's say you have a class library project that has any number of supplemental
Let's say I have many items with click event (all have same element name
Let's say I have a domain object with the following field: private Map<StatType, Double>
Let's say I have such MYSQL table for logins: id---name---location---login_date ---------------------------------- 1----mike----usa-----21.08.2012 2----tony----uk------22.08.2012 3----tony----uk------23.08.2012
Let's say you have a class, with certain properties, and that you tried your
Let's say I have a Person class with FirstName and LastName . I want
Let say you have an XML like this: <?xml version=1.0 encoding=utf-8?> <Class HashCode=307960707> <Person>

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.