0

This is my object,

$scope.addresses = [
        {
            "addressLine1": "150 Address",
            "addressLine2": "LONDON",
            "addressLine3": "",
            "addressLine4": "EC00 00X"
        },
        {
            "addressLine1": "152 Address",
            "addressLine2": "LONDON",
            "addressLine3": "",
            "addressLine4": "EC00 00X"
        },
        {
            "addressLine1": "154 Address",
            "addressLine2": "LONDON",
            "addressLine3": "",
            "addressLine4": "EC00 00X"
        }
    ];

This is my select HTML

<select  ng-model="model.addressChoice" ng-options="(a.addressLine1+ ', '+ a.addressLine2+ ', '+ a.addressLine3+ ', '+ a.addressLine4) for a in addresses">
            <option value="" disabled selected>{{select.length}} Address's Found</option>
        </select>

I've found that when using model.addressChoice = addresses[2] it will populate the select field although should I use

mode.addressChoice = {
                "addressLine1": "154 Address",
                "addressLine2": "LONDON",
                "addressLine3": "",
                "addressLine4": "EC00 00X"
            }

This fails, why is that? I've set up a plunkr here as an example as well.

https://plnkr.co/edit/BtxMDP0mtJx4m7PTLD6B?p=preview

2
  • Remove " disabled selected " and try it Commented Apr 19, 2016 at 10:14
  • I think the value of your model should be an instance of your options (adresses) object or array. Commented Apr 19, 2016 at 10:16

2 Answers 2

3

It fails because you're creating another instance with this code:

        mode.addressChoice = {
            "addressLine1": "154 Address",
            "addressLine2": "LONDON",
            "addressLine3": "",
            "addressLine4": "EC00 00X"
        }

and "addresses" array, which setted in ng-options attribute, doesnt contains this elem. You should use only links to objects from "addresses" collection.

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

1 Comment

@Liably - you should mark this as the correct answer.
0

Remove disabled selected inside option tag

    <select  
            ng-model="model.addressChoice" 
            ng-options="(a.addressLine1+ ', '+ a.addressLine2+ ', '+ a.addressLine3+ ', '+ a.addressLine4) for a in addresses">

            <option value="">{{select.length}} Address's Found</option>
 </select>

When loading selected " 3 Address's Found "

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.