1

I have a json array formatted like this:

share.videos = [
  {
    sources: [
      {src: $sce.trustAsResourceUrl('http://example.com/Inner_Strength.mp4'), type: 'video/mp4'},
      {src: $sce.trustAsResourceUrl('http://example.com/Inner_Strength.webm'), type: 'video/webm'},
      {src: $sce.trustAsResourceUrl('http://example.com/Inner_Strength.ogv'), type: 'video/ogg'}
    ],
    info: [
      {
        'title': 'Inner Strength',
        'videoFile': 'Inner_Strength_HD.mp4'
      }
    ]
  }]

I would like to use ng-options to get the title from info.title

ng-options="i.info.title for i in share.videos"

Gives me blank labels in my select element on my DOM, but with the right amount of options.

Is it possible to use ng-options with an array formatted like this?

3 Answers 3

1

info is an array not object.

You have to specify it's index.

Try like this

ng-options="i.info[0].title for i in share.videos"
Sign up to request clarification or add additional context in comments.

Comments

0

You can try something like this:

ng-options="video in share.videos"
    ng-options="inf in video.info"
        {{inf.title}}

Comments

0

I believe your info has multiple titles like below -

share.videos = [
  {
    sources: [
      {src: $sce.trustAsResourceUrl('http://example.com/Inner_Strength.mp4'), type: 'video/mp4'},
      {src: $sce.trustAsResourceUrl('http://example.com/Inner_Strength.webm'), type: 'video/webm'},
      {src: $sce.trustAsResourceUrl('http://example.com/Inner_Strength.ogv'), type: 'video/ogg'}
    ],
    info: [
      {
        'title': 'Inner Strength',
        'videoFile': 'Inner_Strength_HD.mp4'
      },
      {
        'title': 'Another Title',
        'videoFile': 'Inner_Strength_HD_another.mp4'
      },

    ]
  }]

In this case, you should use it like -

ng-options="i.title for i in share.videos[0].info"

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.