greenoldman greenoldman - 1 year ago 72
AngularJS Question

Why does Angular still add unknown selection?

I am pretty new to Angular so I am missing something trivial:

<select ng-model="shop_index">
<option ng-repeat="elem in shops"

When I look at created HTML code it looks fine except for that unknown entry. I add
to HTML code -- no change. I init the model value in controller (before fetching the data) -- no change. I init the model after fetching the data -- no change. This unknown option is simply welded :-).

I am not asking how to get rid of it (like adding it manually, but hidden) but how to fix the above code to remove it automatically.

Answer Source

You should use this:

In your controller:

$scope.shop_index = $scope.shops[0];

In your view:

<select ng-model="shop_index" ng-options="elem as for elem in shops"></select>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download