Created
January 17, 2014 19:26
-
-
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…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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