{{ item }}
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-my-component',
templateUrl: './my-component.component.html',
styleUrls: ['./my-component.component.scss']
})
export class MyComponentComponent implements OnInit {
items: string[] = ['apple', 'banana', 'cherry', 'date', 'elderberry'];
filteredItems: string[];
ngOnInit() {
this.filteredItems = this.items;
}
optionSelected(event) {
// do something, such as redirecting to another page
}
filterItems(evt) {
const start = evt.target.value.toLowerCase();
this.filteredItems = this.items.filter(item =>
item.toLowerCase().indexOf(start) === 0);
}
}
上一篇:Angular自动刷新数据