【发布时间】:2015-02-25 20:46:45
【问题描述】:
我将此过滤器添加到我的 Angular 应用程序中以从加载的数据中删除某些字符串:
.filter('cleanteam', function () {
return function (input) {
return input.replace('AFC', '').replace('FC', '');
}
});
<h2 class="secondary-title">{{teamDetails.name | cleanteam }}</h2>
你可以在这里看到错误:
http://alexanderlloyd.info/epl/#/teams/61
我的控制器看起来有点像这样:
.controller('teamController', function($scope, $routeParams, footballdataAPIservice) {
$scope.id = $routeParams.id;
$scope.team = [];
$scope.teamDetails = [];
//$scope.pageClass = '';
$scope.$on('$viewContentLoaded', function(){
$scope.loadedClass = 'page-team';
});
footballdataAPIservice.getTeam($scope.id).success(function (response) {
$scope.team = response;
});
footballdataAPIservice.getTeamDetails($scope.id).success(function (response) {
$scope.teamDetails = response;
});
})
为什么会发生这种情况?是不是因为 teamDetails.name 没有在 ng-repeat 循环中声明?
【问题讨论】:
-
您的过滤器应该在更换内部过滤器之前处理未定义的条件
标签: javascript angularjs angularjs-filter