Patrick Cauley
Patrick Cauley

Reputation: 971

NG Select from array there has to be a better way

I have an array of options, they are static and won't be changing my preference was to simply do a standard select with ng-model attached and then add my options. As far as I can tell this doesn't really work as the model does not bind. Fine. I'll do it the Angular way which is the first time I've seen the Angular way take so much more than any other way.

So I have my array

$scope.options = ['1', '2' 'Etc'];

Then the select:
<select ng-model="stupidAngular" ng-options="options as options for options in options"></select>

Is there a better way to bind the model to a select in angular?

Upvotes: 0

Views: 87

Answers (1)

apohl
apohl

Reputation: 1923

Here is an example:

<select ng-model="selectedGroup" ng-options="group.title for group in groups">
   <option value="">-- choose group --</option>
</select>

$scope.groups = [
    {
        title: "option 1"
    },
    {
        title: "option 2"
    },
    {
        title: "option 3"
    }
];

There is also good documentation here.

Upvotes: 1

Related Questions