1

I am trying to get the url of the selected option. So my main goal is to assign the selected option to the ng-model of the select

HTML:

<select ng-model="ddValue1.value">
    <option ng-repeat="d in ddOptions1" value="{{d.value}}">{{d.text}}</option>
</select>

JS:

$scope.ddOptions2 = [
  {value: 'value1', text: 'Text1', url: 'google.com'},
  {value: 'value2', text: 'Text2', url: 'yahoo.com'}
];
$scope.ddValue2 = {};
$scope.ddValue2.value = $scope.ddOptions2[0].value;

I tried assigning it by doing ng-model="ddValue1.url=d.url"

1
  • 2
    Use ng-options not ng-repeat... See docs Commented Aug 2, 2016 at 0:22

2 Answers 2

1

Use ng-options like this

<select ng-model="ddValue1"
    ng-options="d.text for d in ddOptions1 track by d.value">
</select>

Then you can simply reference ddValue1.url

Sign up to request clarification or add additional context in comments.

3 Comments

@user4756836 not sure what you mean. There is no ng-option
sorry, meant... ng-repeat
@user4756836 why? ng-options works much better
0

There is a typo error in ng-repeat. call ddOptions2

<option ng-repeat="d  in ddOptions2" value="{{d.value}}">{{d.text}}</option>

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.