0

The results.session_id has a red squiggly on it because it is an unknown parameter. How do I let Angular/TS that it is a valid parameter?

```
this.requestManager.loginRequest(email, password).subscribe(
  result => {
    localStorage.setItem('session_id', result.session_id)
    this.router.navigate(['/discover'])
  },
  error => {},
  () => {}
)
0

1 Answer 1

2

You can use bracket notation to access the property:

this.requestManager.loginRequest(email, password).subscribe(
  result => {
    localStorage.setItem('session_id', result['session_id'])
    this.router.navigate(['/discover'])
  },
  error => {},
  () => {}
)

Otherwise the better option could be creating an interface to represent the “result” and use HttpClient get() with a type in your service:

interface Session {
  session_id: string;
}

this.http.get<Session>(“some-url”);

Hopefully that helps!

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Just what I was looking for.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.