2

Searched for a solution in other questions but nothing helped me..

I wish to redirect to url like,

this.router.navigateByUrl('/products');

In which i need to pass the array and need to get it it in the component which has the active link products using skip location change without showing anything in url.

Array will be like,

products = [{"id":1,"name":"Product One","id":2,"name":"Product Three","id":3,"name":"Product Six"}]

I need to pass this entire array in router link and need to retrieve it in another component (products) active link using skipLocation Change true..

Tried with sharedService but i am getting issue of data loading at right point of time and hence i decided to use via router link..

If this is not a good approach, kindly suggest other alternative without using sharedservice..

7
  • 1
    Either you can use the Query string or Session Storage to implement this functionality. Commented Nov 27, 2018 at 7:39
  • also could create a service to do the same : angular.io/guide/component-interaction#!#bidirectional-service Commented Nov 27, 2018 at 7:41
  • Use shared service either Commented Nov 27, 2018 at 7:41
  • Possible duplicate of stackoverflow.com/questions/42412110/… Commented Nov 27, 2018 at 7:41
  • @PardeepJain, Using shared service i am facing problem of latency and so i wish to make this approach.. Commented Nov 27, 2018 at 7:41

1 Answer 1

1

You can use Angular Services for a large data.

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { Subject } from 'rxjs/Subject';

@Injectable()
export class ExampleService {

private subject = new Subject<any>();  

updateRouteData(data) {
    this.subject.next(data);
}

routeData(): Observable<any> {
    return this.subject.asObservable();
}
}

In your components;

For set route data;

import { ExampleService } from '/example.service'

export class ComponentOne{

constructor(private exampleService:ExampleService){
   this.exampleService.updateRouteData(data)
}

You can pass data like;

import { ExampleService } from '/example.service'

export class ComponentTwo{

constructor(private exampleService:ExampleService){
   this.exampleService.routeData().subscribe(data => {
       console.log(data)
   })
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.