Angularjs ng checked directive
The ng-checked
directive in AngularJS allows you to bind a checkbox or radio button to a boolean value. Here's an example:
<input type="checkbox" ng-model="isChecked" ng-checked="myCondition">
In this example, we're using the ng-model
directive to bind the value of the checkbox to the isChecked
variable. We're also using the ng-checked
directive to bind the checkbox to the value of myCondition
, which is a boolean value that you define in your controller.
If myCondition
is true, the checkbox will be checked by default. If myCondition
is false, the checkbox will be unchecked by default.
Here's an example of how you might define myCondition
in your controller:
app.controller('MyController', function($scope) { $scope.myCondition = true; });
In this example, we're using the app.controller
method to define a new controller called MyController
. Within the controller, we define the myCondition
variable and set it to true
.
When the page loads, the checkbox will be checked by default because myCondition
is true.
Note that the ng-checked
directive should only be used when you need to bind a checkbox or radio button to a boolean value. In most cases, you should use the ng-model
directive to bind form inputs to variables.