Keep Same Data When Page Refreshed Angular 6

Discussão em 'Angular' iniciado por Zain Khan, Outubro 24, 2024.

  1. Zain Khan

    Zain Khan Guest

    I'm getting data on button click from WebAPI and navigate the component to other component to show this data and this trick is working fine for me but the issue is when I refresh the page my data is empty, Please provide me some solution or example to keep same data. Thanks in advance

    component.ts //where I'm getting data onClick

    onSubmit(){
    this.departmentService.GetDepartmentSearchResults(this.modelSearch1.value.Department, this.modelSearch1.value.Year, this.modelSearch1.value.No).subscribe(res => {
    this.objDepartmentsSearchedResults = res as DepartmentsSearchedResultsModel[];
    this.departmentService.objDepartmentsSearchedResults = this.objDepartmentsSearchedResults;
    this._router.navigate(['departments/search-results']);
    });
    }


    service.ts //where I'm passing data to varaible

    objDepartmentsSearchedResults: DepartmentsSearchedResultsModel[];


    Other component.ts //where I want to show this data

    ngOnInit(){
    console.log("results listing : ", this.departmentServices.objDepartmentsSearchedResults);
    }

    Continue reading...

Compartilhe esta Página