Angularjs 与选择和复选框的关系

Angularjs 与选择和复选框的关系,angularjs,select,checkbox,element,Angularjs,Select,Checkbox,Element,在此之后,我需要在“选择”中选择选项,并在复选框中选中一些值。 但问题是,当我选择select选项时,我无法选中复选框。 我想问题出在“expect(element…”这一行上 从您的plunker代码中,我看到您的角色ID是int类型,您选择的值是string类型。在您的if条件下,您正在进行一次硬检查(==检查类型和值) 解决方案: 或者更改您的值类型并保持它们不变 修复你的状况 在检查之前,请将它们铸造为相同 试试这个 $scope.isChecked = function(id, ma

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


从您的plunker代码中,我看到您的
角色ID
int
类型,您选择的值是
string
类型。在您的
if
条件下,您正在进行一次硬检查
(==检查类型和值)

解决方案:

  • 或者更改您的值类型并保持它们不变
  • 修复你的状况
  • 在检查之前,请将它们铸造为相同
  • 试试这个

    $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);
      }
    });
    

    };

    我修复了它,但在控制台中,此消息:ReferenceError:expect未设置,我无法修复。请尝试以下操作:
    $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);
      }
    });