使用ngFor建立<ion-list radio-group>

Fra*_*sco 5 ionic2

我正在尝试从数组中使用* ngFor建立一个离子列表无线电组。我有一系列的游戏(id,name),我只想要一个列表,用户只能选择一个列表,但是局部变量似乎坏了(应该检查第一个变量,但这也不起作用)。这是我的代码:

<ion-header>
 <ion-navbar>
    <ion-title>
        New match
    </ion-title>
 </ion-navbar>
</ion-header>

<ion-content>
 <ion-list radio-group>
    <ion-list-header>
        Game
    </ion-list-header>
    <ion-item *ngFor="let game of games, let i = index">
        <ion-label>{{ game.name }}</ion-label>
        <ion-radio checked="i == 0" value="game.id"></ion-radio>
    </ion-item>
 </ion-list>
</ion-content>
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?有人有主意吗?谢谢。

Joh*_*ohn 4

您必须{{}}checked="i==0"和之间使用双括号value="game.id",如下所示:

<ion-radio checked="{{i == 0}}" value="{{game.id}}"></ion-radio>

否则,checkedvalue属性将内容计算为字符串,而不是表达式。