Skip to content

Instantly share code, notes, and snippets.

@zymsys
Created January 17, 2014 19:26
Show Gist options
  • Save zymsys/8479765 to your computer and use it in GitHub Desktop.
Save zymsys/8479765 to your computer and use it in GitHub Desktop.
Trying to solve the 'Explore More' challenge from https://github.com/angular/angular.dart.tutorial/wiki/Introducing-filters-and-services, but I can't find the right approach to a filter which modifies the output. This loops forever because the list is changed by the filter. For now this just prepends an x to each ingredient. This is a placeholde…
library multiplier_filter;
import 'package:angular/angular.dart';
import '../recipe.dart';
@NgFilter(name: 'multiplierfilter')
class MultiplierFilter {
call(recipeList, multiplier) {
if (recipeList is List && multiplier is int) {
var result = recipeList.map((recipe) {
List<String> multiplied = [];
recipe.ingredients.forEach((ingredient) {
multiplied.add("x" + ingredient);
});
return new Recipe(
recipe.id,
recipe.name,
recipe.category,
multiplied,
recipe.directions,
recipe.rating,
recipe.imgUrl
);
}).toList(growable: false);
return result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment