angular - 用来自另一个界面的数据填充选择
问题描述
我有一个与另一个合作者链接的表格合作者:区域,在前面,我想在输入新合作者时选择显示可用的区域。问题是,我有一个角度的反应形式,它使用colaborador(西班牙语中的colaborator)界面,但我还有另一个界面区域,所以如何显示数据并以colaborator的形式只保存区域的id ?
export interface Area {
id: number,
nombre: string
}
export interface Colaborador {
numeroDeIndentificacion: number,
nombres: string,
apellidos: string,
direccion: string,
email: string,
telefono: string,
salario: number,
fk_Area: number,
fechaDeIngreso: Date,
sexo: string,
codigoInterno: number
}
在组件上:
colaborador: Colaborador = {
numeroDeIndentificacion: null,
nombres: null,
apellidos: null,
direccion: null,
email: null,
telefono: null,
salario: null,
fk_Area: null,
fechaDeIngreso: null,
sexo: null,
codigoInterno: null
};
area: Area = {
id: null,
nombre: null
};
areas: Area[] = [];
myForm: FormGroup;
submitted = false;
elCodigoInterno: string;
constructor(private formBuilder: FormBuilder, private dataService: DataService) { }
iniciarFormulario(){
this.myForm = new FormGroup({
numeroDeIndentificacion: new FormControl(this.colaborador.numeroDeIndentificacion, [Validators.required, Validators.minLength(4), Validators.maxLength(30)]),
area: new FormControl('')
});
}
ngOnInit() {
this.dataService.obtenerAreas().subscribe(
//result => console.log('success ', result),
result => this.areas = result,
error => console.log('error ', error)
);
this.iniciarFormulario();
}
onSubmit() {
this.submitted = true;
if (this.myForm.invalid) {
alert ('Error')
return
}
this.dataService.RegistrarColaborador(this.myForm.value).subscribe(
result => console.log('success ', result),
error => console.log('error ', error)
);
}
在html上:
<select class="area-select" (change)="onSelect($event)" formControlName="area">
<option value="" disabled>Seleccionar Area</option>
<option *ngFor="let area of areas" [ngValue]="area.id">{{area.nombre}}</option>
</select>
解决方案
推荐阅读
- java - Java:如何解析 Oracle DB 表中的 XML 类型列数据?
- ios - FBAudienceNetwork for iOS 静态还是动态?
- curl - 正方形 INVALID_REQUEST_ERROR
- svg - 如果我现在使用文本,如何在 svg 中显示分数
- python - BeautfilSoup Python,获取两个标签之间的所有文本
- c++ - 打开与 Qt/C++ 的数据库连接
- python-3.x - python 的 pandas.DataFrame 函数有什么替代方法吗?
- ios - 如何从方形阅读器 sdk 中删除结果弹出窗口
- ruby-on-rails - Rails High_Voltage 错误:#<# 的未定义方法“page_path”
- flutter - 如何将 Flutter 应用中的帖子分享到 inkedIn、facebook 等社交媒体平台?