收集于angular2怎样根据接口获取的值来选中input[radio]和select?
app.html
// select绑定的是value
<select [(ngModel)]="comId">
<option [value]="c.id" *ngFor="let c of comIdList">{{c.name}}</option>
</select>
// radio绑定的是value
<label *ngFor="let t of typeList">
<input type="radio" name="type" [(ngModel)]="type" [value]="t.id">{{t.name}}
</label>
app.component.ts
@Component({
selector: 'app',
templateUrl: 'src/app.html'
})
export class AppComponent implements OnInit {
comIdList:any = [
{id: 1, name: '中国公司'},
{id: 2, name: '美国公司'},
{id: 3, name: '德国公司'}
];
typeList:any = [
{id: 1, name: '类型A'},
{id: 2, name: '类型B'}
];
comId:number;
type:number;
constructor() {
}
ngOnInit() {
setTimeout(()=> {
this.comId = 3;
this.type = 2;
}, 1000);
}
}