1

In my Razor view I am using Angular and trying to pass the value of a checkbox to function.

When the following input is checked"

<label><input id="divpriority" ng-model="priority" type="checkbox" />
  Select all - high priority
</label>

This input is changed:

<label><input class="tablePriority" ng-checked="priority" type="checkbox" />
   High priority
</label>

Now I am trying to pass the value(true/false) in the above input to a function:

<td><br/><br/>
  <button id="enqueuebtn"  type="button" ng-click="Enqueue(priority)" 
          class="btn-primary">Enqueue</button>
</td>

This is not working as priority is undefined when I am debugging my JavaScript.

How can I pass the value true/false to function Enqueue when the second input is checked ?

In my JavaScript I have:

$scope.Enqueue = function (isPriority, ) {
    debugger;

While debugging idPriority is undefined.

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Milligran
  • 3,031
  • 9
  • 44
  • 56
  • Post your JavaScript too. – Eric Hotinger Sep 17 '13 at 16:46
  • can you post more HTML code too, or maybe a jsfiddle? – kmdsax Sep 17 '13 at 17:21
  • New AngularJS developers often do not realize that `ng-repeat`, `ng-switch`, `ng-view`, `ng-include` and `ng-if` all create new child scopes, so the problem often shows up when these directives are involved. See [nuances of protoypical inheritance](https://stackoverflow.com/questions/14049480/what-are-the-nuances-of-scope-prototypal-prototypical-inheritance-in-angularjs). – georgeawg Mar 07 '20 at 00:30

2 Answers2

0

Priority should be available in your controller, since you are binding to it. So from your edit, this line is not needed:

 $scope.priority = isPriority;

since $scope.priority should already reflect the value of the checkbox.

Phil Sandler
  • 27,544
  • 21
  • 86
  • 147
0

Added model to second input

<label><input ng-model="ispriority" class="tablePriority" ng-checked="priority" type="checkbox" />High priority</label>

Then pass model to function:

<td><br/><br/><button id="enqueuebtn"  type="button" ng-click="Enqueue(ispriority)" class="btn-primary">Enqueue</button></td>
Milligran
  • 3,031
  • 9
  • 44
  • 56