Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS checkbox checked custom value

I'm trying to have a box checked by default with a custom value.

Are you ready? <input type="checkbox" ng-model="checked" ng-init="checked=true" ng-true-value="sure" ng-false-value="nope"><br/>
<tt> {{checked}}</tt><br/>

If I set it to that nothing displays until I click the box. Is there a way to where it can be checked with a default value being something other than a boolean value?

like image 877
Sethe23 Avatar asked Jul 25 '14 03:07

Sethe23


1 Answers

ng-true-value="sure". So, ng-init="checked='sure'"

Code Snippet

<input type="checkbox" ng-model="checked" ng-init="checked='sure'" ng-true-value="sure" ng-false-value="nope">

Plunkr - http://plnkr.co/edit/ejYSsyIjMZSZua9cQyv1?p=preview

like image 70
hutingung Avatar answered Oct 19 '22 02:10

hutingung