0

I want to filter an array of 'forms' by their 'id' and then return its 'fields'.

Currently I have this - but nothing is returned:

<select ng-options="option.displayName for option in forms.fields track by option.id|filter: {'id': component.form.id}" ng-model="component.field"></select>

The filtering on 'forms' works fine if I just want the complete form object, forms|filter: {'id': component.form.id}. However I want to get the field names and populate this select with those.

{        
  forms: [   
    {
      id: 1,
      name: 'form 1',
      fields: [
        {
          displayName: 'name 1',
          id: 1
        },
        {
          displayName: 'name 2',
          id: 2
        },
        {
          displayName: 'name 3',
          id: 3
        }
      }
    },
    {
      id: 1,
      name: 'form 1'
      fields: [
        {
          displayName: 'name 1',
          id: 1
        },
        {
          displayName: 'name 2',
          id: 2
        },
        {
          displayName: 'name 3',
          id: 3
        }
      ]
    }
  ]
}

1 Answer 1

0

I had tried this but didn't put the [0], but this works how i wanted.

option.displayName for option in (forms|filter: {'id': component.form.id})[0].fields track by option.id
Sign up to request clarification or add additional context in comments.

Comments

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.