Argument of type 'Params' is not assignable to parameter of type 'string'

3982 views angular
6

I have passed data via snapshot and am now trying to receive it but am getting the following error "[ts] Argument of type 'Params' is not assignable to parameter of type 'string'."

When I sent the data I done a JSON.stringify and the data looked like this.

[
  {
    "caseData": "{\"getAllInfo\":{\"ticket\":{\"internalNum\":\"2500024035\",\"comp\":\"29\",\"reportedDate\":\"2018-07-20\",\"reportedTime\":\"00:00\",\"forceNumCharge\":\"7035551\",\"offenceSequence\":\"1\",\"aggrievedParty\":\"1\"}}}"
  }
]

Now when I try to retrieve the data and do a JSON.parse I get the error mentioned above.

this.caseData = JSON.parse(this.activatedRoute.snapshot.params);

answered question

What type is this.caseData?

it is caseData: any;

1 Answer

3

params is not of type string, which is where you get the error, params is a array that stores the array,

try this adding [0] after ".params":

this.caseData = JSON.parse(this.activatedRoute.snapshot.params[0]);

posted this

Have an answer?

JD

Please login first before posting an answer.