简体   繁体   中英

filter ng-repeat by radio button value

I am struggling to perform filtering in my template by a radio button value.

My data looks like this:

{
 "exerciseDescription": "Take a large step forward in standing and lower the rear knee towards the floor",
 "exerciseName": "Walking Lunge",
 "images": [223, 224, 225],
  "difficulty" : 'Expert'
}

I would like to filter by difficulty however have been unsuccessful in implementing the solutions from here and here

A codepen example is here any assistance on the best way to achieve this would be greatly appreciated.

Additionally I am using angular-masonry if you can foresee any issues it would be great.

-- EDIT--

The correct answer implemented in a codepen is here

The problem is, the ionic direcitves create isolated scopes and the ng-model of your radio inputs only adds the value to this scope, not to the scope of your controller. You can solve this by wrapping the filter property in an object, ie do something like:

$scope.filter = { 'difficulty' : 'Easy' }

...

<input type="radio" ng-model="filter.difficulty" value="Expert" name="group">

See: Angular Wiki - Understanding Scopes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM