zip*_*ppo 5 autocomplete angular-material angular
我正在使用Angular 6和Material 6开发一个简单的页面。我想使用Material的自动完成功能从服务中恢复数据,但是我不知道该怎么做。
从官方示例https://material.angular.io/components/autocomplete/overview我不了解如何使用服务将其与自动完成功能集成。
有谁能够帮助我?
谢谢
最后,我找到了我想做的事情的解决方案!要将 FormArray 绑定到 mat-table 数据源,您必须: 简而言之,示例如下:
<table mat-table [dataSource]="itemsDataSource">
<ng-container matColumnDef="itemName">
<td mat-cell *matCellDef="let element">{{ element.value.material?.name }}</td>
</ng-container>
<ng-container matColumnDef="itemCount">
<td mat-cell *matCellDef="let element">{{ element.value.itemCount }}</td>
</ng-container>
<tr mat-row *matRowDef="let row; columns: itemColumns;"></tr>
</table>
Run Code Online (Sandbox Code Playgroud)
和代码:
export class ItemListComponent implements OnInit {
constructor(
private fb: FormBuilder
) { }
itemColumns = ['itemName', 'count'];
itemForm: FormGroup;
itemsDataSource = new MatTableDataSource();
get itemsForm() {
return this.itemForm.get('items') as FormArray;
}
newItem() {
const a = this.fb.group({
material: new FormControl(), //{ name:string }
itemCount: new FormControl() // number
});
this.itemsForm.push(a);
this.itemsDataSource._updateChangeSubscription(); //neccessary to render the mat-table with the new row
}
ngOnInit() {
this.itemForm = this.fb.group({
items: this.fb.array([])
});
this.newItem();
this.itemsDataSource.data = this.itemsForm.controls;
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
12289 次 |
最近记录: |