【问题标题】:Relationship with select and checkbox angular与选择和复选框角度的关系
【发布时间】:2017-09-09 18:12:24
【问题描述】:

我需要在 select 中选择选项并在此之后检查复选框中的一些值。 但问题是当我选择选择选项时,我无法选中复选框。 我猜问题出在“expect(element...”)这一行

CODE plunker

$scope.isChecked = function(id, matches){
    angular.forEach(matches,function(match) {
      if(match === id){
        expect(element(by.id('check'+match)).getAttribute('checked')).toBeTrue();
      }
    });
    $scope.calculatedValue = 'You selected number ' + id +" and have "+ matches;
  };

【问题讨论】:

    标签: angularjs select checkbox element


    【解决方案1】:

    试试这个。

    $scope.isChecked = function(id, matches){
    angular.forEach(matches,function(match) {
      if(match.toString() === id){
            console.log(match);
        $scope.calculatedValue = 'You selected number ' + id +" and have "+ matches;
        angular.element(document.getElementById('check' + match).checked = true);
      }
    });
    

    };

    【讨论】:

      【解决方案2】:

      从您的 plunker 代码中,我看到您的 role ids 是 int 类型,而您的选择值是 string 类型。在你的if 条件下,你正在做一个艰苦的检查(=== check type and value)

      解决方案:

      1. 要么更改值类型并保持不变。
      2. 修复您的状况。
      3. 在检查它们是否相同之前。

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-10-13
      • 1970-01-01
      • 2017-08-27
      • 1970-01-01
      • 2022-11-28
      • 1970-01-01
      • 2015-04-02
      相关资源
      最近更新 更多