【发布时间】:2019-08-31 20:22:15
【问题描述】:
我有一个从 web api 获取数据的 Angular 应用程序。我的页面中还有一个表单,它有一个隐藏字段,需要从该 api 发送值:number。我已经尝试了以下代码,但它不起作用:
ts.component 文件。
receivedIncident: any;
number: any;
constructor(private service: nowService,
private appComponent: AppComponent,
private userService: UserService,
private router: Router,
private http: HttpClient,
private route: ActivatedRoute
) {
this.receivedIncident = { number: '', opened_at: '', description: '', short_description: ''}; this.receivedLocation = {city:null, country: null}
}
private getIncident() {
this.service.getIncident(this.s_id, this.c_id).subscribe((data) => {
this.loading = true;
console.log('Result - ', data);
console.log('incident data is received');
this.loading = true;
this.receivedIncident = data.result[0];
})
}
ngOnInit() {
this.loading = true;
this.getIncident();
this.loading = true;
})
this.addCommentsForm = new FormGroup({
comment: new FormControl(''),
c_id: new FormControl(this.customer_id),
number: new FormControl(this.receivedIncident.number),
})
}
html 表单域
<input name="number" class="form-input" type="hidden" id="number" value="number
有什么想法吗?
【问题讨论】:
-
在调用 API 之前先创建表单。如果您的输入在表单中,则将
formControlName='number'添加到输入中,如果不是,则将formControl作为输入属性添加到输入 -
你能详细说明吗?
-
@Sole 检查我的答案如下
标签: angular