1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Angularjs ng-checked="$index == (defaultCk || 0)" メモ

Posted at

ng-checked で入力値が無い場合、デフォルトで0番目のチェックボックスを有効にしたかった。

ng-repeat で複製される ラジオボタンです。

<li ng-repeat="radio in radios" ng-init="defaultCk= "myCheckValue">
    <input type="radio" name="myRadio" value="{{$index}}" ng-checked="$index == (defaultCk || 0)">
</li>

myCheckValue に値が無い場合、defaultCk は undefined になるので、
ng-checked="$index == (defaultCk || 0)" の部分で、 0$index に代入されるため、
value="{{$index}}" は  0 が入ります。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?