angular2怎样根据接口获取的值来选中input和select
2017-08-25 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
app.html
<select [(ngModel)]="comId">
<option [value]="c.id" *ngFor="let c of comIdList">{{c.name}}</option>
</select>
<div>
<label *ngFor="let t of typeList">
<input type="radio" (change)="type=t.id" name="type" [checked]="type===t.id">{{t.name}}
</label>
</div>
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);
}
}
<select [(ngModel)]="comId">
<option [value]="c.id" *ngFor="let c of comIdList">{{c.name}}</option>
</select>
<div>
<label *ngFor="let t of typeList">
<input type="radio" (change)="type=t.id" name="type" [checked]="type===t.id">{{t.name}}
</label>
</div>
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);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询