我想实现以下理论代码:
VIEW.html
<li ng-repeat="player in players | filter:myCustomFilter(player)">{{player.name}}
Run Code Online (Sandbox Code Playgroud)
CONTROLLER.js
// some theoretical conditional statement that return a boolean
$scope.otherCondition = true;
$scope.myCustomFilter = function(player) {
return player.name.substring(0,1).match(/A/gi) && $scope.otherCondition;
}
Run Code Online (Sandbox Code Playgroud)
所以我希望所有玩家都加载到Angular模型中,但我只想将玩家渲染到名称以字母"A"开头的DOM中.当我尝试做这样的事情时,我的控制台告诉我这player是未定义的.我是否需要编写自定义过滤器才能实现此目的(通过angular.module().filter())?