Jeremy Miller Jeremy Miller - 1 month ago 13
AngularJS Question

Input type checkbox Angular to be checked if object value is string of 1

In my controller I have object of properties in which

isSampleData = "1"


this is a string value and if it is "1" then I want the checkbox to be checked

Controller is

$scope.client


HTML template

<strong>{{client.IsSampleData}}</strong>


However I want to not have it in a template but as a checkbox

Can and Should I use ng-model ?

<input type="checkbox"
ng-model="string"
value="string"
ng-value="string"/>


Obviously that code is not using the
client.IsSampleData

Answer

You can also specify value of client.IsSampleData, when checkbox will be unchecked, at example it is '0':

<input type="checkbox" ng-model="client.IsSampleData" ng-true-value="'1'" ng-false-value="'0'">
Comments