AngularJs - 在点击时添加活动类的最佳实践(ng-repeat)

14 浏览
0 Comments

AngularJs - 在点击时添加活动类的最佳实践(ng-repeat)

我想在点击时向列表中添加一个active类,我尝试了以下代码,但它会将active类添加到所有的项目中:/:

HTML:

    
  • {{filters.time}}

Js:

  var filters = [
            {
                'filterId': 1,
                'time': '过去24小时',
            },
            {
                'filterId': 2,
                'time': '全部',
            },
            {
                'filterId': 3,
                'time': '过去一小时',
            },
            {
                'filterId': 4,
                'time': '今天',
            },
            {
                'filterId': 5,
                'time': '昨天',
            }
        ]; 
function selectFilter($scope) {
    $scope.items = ['filters'];
    $scope.selected = $scope.items[0];
    $scope.select= function(item) {
       $scope.selected = item; 
    };
}

请给我一些帮助。

谢谢。

0