这里有一款类似的应用程序正在运行.与您的代码进行比较.我使用了[checked]
属性.
import 'zone.js/dist/zone';
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { bootstrapApplication } from '@angular/platform-browser';
@Component({
selector: 'my-app',
standalone: true,
imports: [CommonModule],
template: `
<div *ngFor="let payMode of payModes">
<input type="radio" name="pm" [value]="payMode.id" [checked]="selectedPayMode === payMode.id" />
{{ payMode.name }}
</div>
`,
})
export class App {
payModes = [
{
id: 1,
name: 'Monthly'
},
{
id: 2,
name: 'Quarterly'
},
{
id: 3,
name: 'Yearly'
}
];
selectedPayMode = 2;
}
bootstrapApplication(App);