页面刷新后如何保存PrimeNG下拉项的下拉值?
https://www.primefaces.org/primeng/#/dropdown
HTML
<p-dropdown [options]="cities2" [(ngModel)]="selectedCity2" optionLabel="name"></p-dropdown>
打字稿
import {SelectItem} from 'primeng/api';
interface City {
name: string;
code: string;
}
export class MyModel {
cities2: City[];
selectedCity2: City;
constructor() {
//An array of cities
this.cities2 = [
{name: 'New York', code: 'NY'},
{name: 'Rome', code: 'RM'},
{name: 'London', code: 'LDN'},
{name: 'Istanbul', code: 'IST'},
{name: 'Paris', code: 'PRS'}
];
}
ngOnInit(){
localStorage.setItem('key', this.selectedCity2);
const getItem = localStorage('key');
this.selectedCity2 = getItem;
}