最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - AngularJS checkbox checked custom value - Stack Overflow

programmeradmin2浏览0评论

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?

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?

Share Improve this question asked Jul 25, 2014 at 3:41 Sethe23Sethe23 2,6624 gold badges20 silver badges18 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 12

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

发布评论

评论列表(0)

  1. 暂无评论