1

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..

Maniraj Murugan
  • 8,868
  • 20
  • 67
  • 116

1 Answers1

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)
   })
}
Kıvanç B.
  • 152
  • 4