扫码关注官方订阅号
angular2怎样根据接口获取的值来选中input[radio]和select?
认证0级讲师
<select [(ngModel)]="comId"> <option [value]="c.id" *ngFor="let c of comIdList">{{c.name}}</option> </select> <p> <label *ngFor="let t of typeList"> <input type="radio" (change)="type=t.id" name="type" [checked]="type===t.id">{{t.name}} </label> </p>
@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); } }
先遍历下接口获取到的值 if(true){selectbox[i]= checked}
if(true){selectbox[i]= checked}
[(ngModel)]
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
app.html
app.component.ts
先遍历下接口获取到的值
if(true){selectbox[i]= checked}[(ngModel)]