【发布时间】:2019-03-20 22:43:16
【问题描述】:
嗨,我是 Angular 的初学者,我想显示材料自动完成文本视图 在离子应用程序中,我按照下面的博客来满足我的要求https://material.angular.io/components/autocomplete/overview 但是当我运行我的代码时,它会显示在屏幕上,如下图所示,但我想在输入字段的下方显示,就像它们在博客中的显示方式一样有人可以建议请给我
home.css
page-home {
.example-form {
min-width: 150px;
max-width: 500px;
width: 100%;
}
.example-full-width {
width: 100%;
}
}
home.html
<ion-content padding>
<form class="example-form">
<mat-form-field class="example-full-width">
<input type="text" placeholder="Pick one" aria-label="Number" matInput [formControl]="myControl" [matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete">
<mat-option *ngFor="let option of options" [value]="option.name">
{{ option.name }}
</mat-option>
</mat-autocomplete>
</mat-form-field>
</form>
</ion-content>
home.ts:
export class HomePage implements OnInit {
myControl = new FormControl();
options: string[] = ['One', 'Two', 'Three'];
filteredOptions: Observable<string[]>;
ngOnInit() {
this.filteredOptions = this.myControl.valueChanges.pipe(
startWith(''),
map(value => this._filter(value))
);
}
private _filter(value: string): string[] {
const filterValue = value.toLowerCase();
return this.options.filter(option =>
option.toLowerCase().indexOf(filterValue) === 0);
}
}
【问题讨论】:
-
您是否包含主题? material.angular.io/guide/…
-
如何在离子应用程序中做到这一点你能建议我吗?