Попробуйте с localStorage
:
HTML код:
<div *ngFor="let item of people">
<button mat-stroked-button color="primary" [disabled]="item.disabled" (click)="disableItem(item)">Hi</button>
</div>
<button mat-stroked-button color="primary" (click)="reset()">Reset</button>
Код TS:
import { Component } from '@angular/core';
export interface Section {
name: string;
updated: Date;
}
/**
* @title List with sections
*/
@Component({
selector: 'list-sections-example',
styleUrls: ['list-sections-example.css'],
templateUrl: 'list-sections-example.html',
})
export class ListSectionsExample {
people: any[] = [
{
name: 'Photos',
updated: new Date('1/1/16'),
},
{
name: 'Recipes',
updated: new Date('1/17/16'),
}
];
constructor() {
this.people = JSON.parse(localStorage.getItem('people'));
}
reset() {
this.people = [
{
name: 'Photos',
updated: new Date('1/1/16'),
},
{
name: 'Recipes',
updated: new Date('1/17/16'),
}
];
localStorage.setItem('people', JSON.stringify(this.people))
}
disableItem(data) {
data.disabled = true;
localStorage.setItem('people', JSON.stringify(this.people))
}
}
Working Demo