angular 2 retain state from URL after redirect

半腔热情 提交于 2019-12-04 20:46:00

You have several choices:

1) You can retain information on a route using query parameters. That allows you to pass the same parameters back and forth between components.

2) Alternatively, you can build a service to hold onto your shared data. Services are a great way to hold onto data for your application. (But PLEASE don't use BehaviorSubject. It is completely unnecessary in most scenarios.)

I have an example service here:

https://blogs.msmvps.com/deborahk/build-a-simple-angular-service-to-share-data/

The basic service looks like this:

import { Injectable } from '@angular/core';

@Injectable() 
export class DataService {
  serviceData: string; 
}

And a plunker here: https://plnkr.co/edit/KT4JLmpcwGBM2xdZQeI9?p=preview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!