I am trying to filter the values of an array when the page loads, setting a default value in the selection field, but it does not work [when changing the selection field it will filter]
Json
[{
location_id: "2",
location_name: "location2",
price: "40",
product_id: "7",
product_name: "Burger",
quantity: "2"
}, {
location_id: "3",
location_name: "location3",
price: "40",
product_id: "6",
product_name: "Dosa",
quantity: "6"
}, {
location_id: "4",
location_name: "location4",
price: "40",
product_id: "5",
product_name: "cola",
quantity: "16"
}
]
html for Select Box
<select name="location" class="locationFilter col-md-3 col-md-push-9 col-xs-
12" ng-model="location.location_id">
<option value="">--Select location--</option>
<option ng-repeat="item in locationsArray" value="{{item.location_id}}"
ng-selected= "item.location_id == defaultLocation">{{item.location_name}}
</option>
</select>
html to enumerate array
<div class="col-md-3 itemList" ng-repeat="item in productArray |
filter:location">{{item.product_name}}</div>
In the controller, I define a default value for choosing a location, as shown below
$scope.defaultLocation=3;
Any help would be greatly appreciated
source
share