문제

I have a drop down bound to ng-options (which uses an array of objects) and ng-bind (which uses a string). This doesn't work because object comparison fails. Is there a workaround for this?

<select class="form-control"
        ng-model="Person.Gender"
        ng-options="a.name for a in dropdowns.gender">
</select>

Thanks

도움이 되었습니까?

해결책

If I'm not mistaken what you want is to bind the name property to the person.gender property of the $scope. What you need to do is:

<select class="form-control"
        ng-model="Person.Gender"
        ng-options="a.name as a.name for a in dropdowns.gender">
</select>

The first part defines what is actually stored in the ng-model and the second part how is going to display, in this case both displayed value and model value are the same.

Working fiddle: jsfiddle

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top