V SH V SH - 3 years ago 90
AngularJS Question

How to use two ng-modal in one input type in Angular js?

I am using angular js. And implementing input checkbox, So this checkbox checked by default from angular controller using ng-model:

Controller:

var checkBoxVal = true;
$scope.checkboxModel = {
value : checkBoxVal,
}

$scope.call = function(){
alert("--comes--");
if($scope.checkboxModel== false)
{

}
if($scope.mycheckbox== true){

}
}


HTML:

<input type="checkbox" ng-model="checkboxModel.value" data-ng-change="call();"/>


But when call the function "call()" then it is not coming in if condition because $scope.checkboxModel is undefined.
When I use only ng-model="checkboxModel" then it is coming in if condition with true and false. But I want to use both set true value in like ng-model="checkboxModel.value" and compare the checkbox value after calling the call() function.

Answer Source

You don't need two ng-models. Change your condition to this since you want to evaluate based on ng-models value

if($scope.checkboxModel.value)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download