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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:26:41+00:00 2026-06-15T21:26:41+00:00

Given a data structure that contains an array of JavaScript objects, how can I

  • 0

Given a data structure that contains an array of JavaScript objects, how can I bind a certain entry from that array to an input field using Angular?

The data structure looks like this:

$scope.data = {
    name: 'Foo Bar',
    fields: [
        {field: "F1", value: "1F"},
        {field: "F2", value: "2F"},
        {field: "F3", value: "3F"}
    ]
};

The fields array contains several instances of the given structure, with each entry having both a field attribute and a value attribute.

How can I bind an input control to the value field attribute of the array entry with the field F1?

<input ng-model="???"/>

I know that I could bind all fields using an ng-repeat, but that’s not what I want. The above data is just an example from a much larger list of fields, where I only want to bind a pre-defined subset of fields to controls on the screen. The subset is not based on the attributes in the array entries, but is known at design time of the page.

So for the above example, I would try to bind F1 to one input on the page, and F2 to another one. F3 would not be bound to a control.

I’ve seen examples where a function was used in the ng-model, but it doesn’t seem to work with Angular 1.1.0.

Is there another clever way to bind the input field to a specific array entry?

Here’s a fiddle that has an example, but does not work since it’s trying to use function in the ng-model attribute: http://jsfiddle.net/nwinkler/cbnAU/4/

Update

Based on the recommendation below, this is what it should look like: http://jsfiddle.net/nwinkler/cbnAU/7/

  • 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-15T21:26:42+00:00Added an answer on June 15, 2026 at 9:26 pm

    I personally would reorganize the array in a way that field property of an entry of the array become the identifier of the object. Mhhh that sentence may sound strange. What I mean is the following:

    $scope.data = {
        name: 'F1',
        fields: {
            F1: {
               value: "1F"
            },
            F2: {
               value: "2F"
            }
        }
    };
    

    If you want to bind a the value dynamically and it’s an easy and quick way to achieve it.
    Here is your fiddle modified so that it words. http://jsfiddle.net/RZFm6/

    I hope that helps

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

Sidebar

Related Questions

Given an arbitrarily nested data structure, how can I create a new data structure
I have a structure in my program that contains a particular array. I want
I have a table that contains some data given below. It uses a tree
What's the data structure in Java that has the fastest operation for contains() ?
I'm looking for a data-structure, or combination of several, that can give me a
I have an odd linq subquery issue. Given the following data structure: Parents Children
I have a data structure which is as given below: class File { public
Given the following tree structure in Haskell: data Tree = Leaf Int | Node
Given the following XML structure: <root> <data>x</data> <details> <some_other_element>...</some_other_element> <collection> <element><a>1</a></element> <element><a>2</a></element> <element><a>3</a></element> <collection>
Can you give an example where the Queue data structure can be specially helpful

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.