Javascript 如何使用ng repeat在匹配元素上添加活动类

Javascript 如何使用ng repeat在匹配元素上添加活动类,javascript,jquery,angularjs,angularjs-directive,angularjs-ng-repeat,Javascript,Jquery,Angularjs,Angularjs Directive,Angularjs Ng Repeat,我正在进行多重下拉选择,但它也允许单独选择列表项。它不是一个选择元素,而是一个tr,用于保存角度组件中的数据 我在ctrl.checkEquality中的控制器内使用angular.equals来查看当前行和通过ng模型传入的值是否相同,如果它们相同,则所选行将获得活动的绿色类。我基本上想知道我是否可以对我的代码做一些类似的事情,但是设置ng模型,以便在按下“ctrl”键时将活动类应用于多个选定值的数组 <tr ng-repeat="row in ctrl.filteredItems"

我正在进行多重下拉选择,但它也允许单独选择列表项。它不是一个选择元素,而是一个tr,用于保存角度组件中的数据

我在ctrl.checkEquality中的控制器内使用angular.equals来查看当前行和通过ng模型传入的值是否相同,如果它们相同,则所选行将获得活动的绿色类。我基本上想知道我是否可以对我的代码做一些类似的事情,但是设置ng模型,以便在按下“ctrl”键时将活动类应用于多个选定值的数组

 <tr ng-repeat="row in ctrl.filteredItems" ng-class="{'active': ctrl.checkEquality(row, ctrl.ngModel) ng-mousedown="ctrl.onSelectedLocal(row, $event)">
 </tr>

  public onSelectedLocal(row: ng.IAugmentedJQuery, $event: ng.IAngularEvent) {
        if ($event["ctrlKey"]) {
            this.setFocusedRow(-1);
            this.filterText = "";

            // if (this.selectedItems.indexOf(row) === -1) {
            //  this.selectedItems.push(row);
            //  for (var i = 0; i < this.filteredItems.length; i++) {
            //      if (this.filteredItems[i] === row) {

            //      }
            //  }
            // }

            if (this.ngChange) {
                this.ngChange({ itemSelected: row });
            }

            console.log(this.selectedItems);

            //we need to make sure the click event of selecting an item in the dropdown stops here 
            //otherwise it will run into the resetInput function below and not show the selected city in the input element when filterText is used
            $event.preventDefault();
            $event.stopPropagation();

        }  else {
            this.setFocusedRow(-1);
            this.filterText = "";
            this.ngModel = row;
            this.ngModelValue = (this.showSelectedItem === false) ? "" : row[this.itemDisplayProperty];

            if (this.ngChange) {
                this.ngChange({ itemSelected: row });
            }

            this.filteredItems = this.items; //reset filteredItems back to initial items
            this.closeDropdown();

            //we need to make sure the click event of selecting an item in the dropdown stops here 
            //otherwise it will run into the resetInput function below and not show the selected city in the input element when filterText is used
            $event.preventDefault();
            $event.stopPropagation();
        }

我想你错过了
tr
标签中
ng类
末尾的一个结束标签

<tr ng-repeat="row in ctrl.filteredItems" ng-class="{'active': ctrl.checkEquality(row, ctrl.ngModel)" ng-mousedown="ctrl.onSelectedLocal(row, $event)">

好的,谢谢,这只是一个复制粘贴错误。不是它工作的问题。