0

This sounds simple, but googling is coming up trumps. I have a dropdown select that has multiple categories:

<select ng-model="orderProp" >
  <option ng-repeat="cats in categories" value="{{cats}}">{{cats}}</option>
</select>

I also have a map, using Angular Google Maps, which uses JSON data to plot markers. The data for these markers is called $scope.markersProperty

When a users uses the select box, I'd like to dynamically change the value of markersProperty. Using Angular's HTML {{}} I can get the results I want with a simple:

{{markersProperty|filter:orderProp}}

But I can't for the life of me work out how to get similar functionality to update the array $scope.markersProperty. Any ideas?

1
  • Why not use markersProperty as ng-model on select box? Commented Apr 10, 2013 at 1:35

1 Answer 1

2

If you mean you want to update the scope variable, then you can use the $filter service:

.controller('MainCtrl', function ( $scope, $filter ) {
  $scope.markersProperty = // ...

  $scope.$watch( 'orderProp', function ( val ) {
    $scope.filteredMarkersProperty = $filter('filter')($scope.markersProperty, val);
  });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.