var displayyears = [];
$scope.Joinyear=function(display){
$scope.yeardisplay=display;
if (displayyears.indexOf(display) == -1) {
$scope.selected_class[display] = "selected";
displayyears.push($scope.yeardisplay);
}
else{
$scope.selected_class[display] = "";
displayyears.splice($scope.displayyears.indexOf(display),1);
}
它工作但不是正确的方式。假设我有这样的数组[2008,2009,2010,2011]。现在我以随机方式从数组中删除值(在2009之间)意味着它仅移除值2008 ...如何使用Angular JS以随机方式从数组中删除值
答案 0 :(得分:0)
我相信您错误输入了此行中的$scope
:
displayyears.splice($scope.displayyears.indexOf(display),1);
应该是:
displayyears.splice(displayyears.indexOf(display),1);