Data disappears when clicking the back button

Asked

Viewed 140 times

0

I have an application in Angular 2 where I have some data entry screens (inputs). When the user enters the Iprs and clicks to advance, when clicking the Back button, the information disappears. I tried to do something in LocalStorage to persist this data:

PersisteDados() {
    this.LocalStorageService.get('addons');
    this.LocalStorageService.get('contador');
  }

And I called him on onInit() to carry when the view It started, but it didn’t. What would be the best way to make this persistence?

1 answer

0

Use resolve is basically a condition to be met before the view is loaded, in angular, example of documentation

class Backend {
  fetchTeam(id: string) {
    return 'someTeam';
  }
}

@Injectable()
class TeamResolver implements Resolve<Team> {
  constructor(private backend: Backend) {}

  resolve(
    route: ActivatedRouteSnapshot,
    state: RouterStateSnapshot): Observable<any>|Promise<any>|any {
    return this.backend.fetchTeam(route.params.id);
  }
}

@NgModule({
  imports: [
    RouterModule.forRoot([
      {
        path: 'team/:id',
        component: TeamCmp,
        resolve: {
          team: TeamResolver
        }
      }
    ])
  ],
  providers: [TeamResolver]
})
class AppModule {}

in angularjs Angular resolve 1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.