userbb
userbb

Reputation: 1874

ng-model does not update after changing checked property

I have made simple checkbox list with elements such as:

  <li>
    <a href="#">
      <label class="checkbox">
        <input type="checkbox" ng-model="value1" />Aaaaa
      </label>
    </a>
  </li>

Also there is jquery script that highlights row when checkbox is checked and vice-versa it sets .prop("checked") when user clicks <a>(close to item's border). And problem is that I don't know why ng-model doesn't update model when clicking <a>

Here is sample. To reproduce problem click on text (this is ok), and click close to item's border. http://plnkr.co/edit/sStCMaBaU1SsQ7hukfaZ?p=preview

Upvotes: 2

Views: 469

Answers (1)

Mohammad Abbasi
Mohammad Abbasi

Reputation: 322

You can use ng-click directive to slove this problem. I changed your Code:

<li>
    <a href="#" ng-click="ChangeCheckBox">
      <label class="checkbox">
        <input type="checkbox" ng-model="value1" />Aaaaa
      </label>
    </a>
  </li>

and in your Controller:

$scope.ChangeCheckBox = function(){
 var t = $scope.value1;
 $scope.value1 = !t;
}

Upvotes: 1

Related Questions