question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property 'store' of undefined

See original GitHub issue

Hi,

I’m getting an error of TypeError: Cannot read property 'store' of undefined

I’m pretty sure im importing and configuring it right, but here’s a sample of my code:

app.module: import {Ng2Webstorage} from 'ng2-webstorage'; browser module, etc

and then in my service: `import {LocalStorageService} from ‘ng2-webstorage’; @Injectable() export class LoginService {

constructor (private http: Http,  private storage:LocalStorageService) {}
private saveTokenId(res: Response) {
    let body = res.json();
    let success: boolean;
    try {
        this.storage.store('userId', 'value');
        success = true;
    } catch(e){
        console.log(e)
        success = false;
    } finally {
        return success
    }
}`

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
PillowPillowcommented, Oct 7, 2016

Yes, that was the tricky part 😃. You juste have to use a lambda function and it will works like a charm.


sendToken (token: string): Observable<any> {
    let body = 'token='+token;
    let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
    let options = new RequestOptions({ headers: headers });
    return this.http.post('http://localhost:3200', body, options)
        .map((...params) => this.saveTokenId(...params))
        .catch((...params) => this.handleError(...params));
}


Also guessing because I’m calling the saveTokenId as private?

No, that’s just that you pass the this.saveTokenId function directly to map as a callback, so you lose the context. You juste have to keep it by binding the function or wrapping the statement by a lambda fn.

0reactions
PillowPillowcommented, Oct 7, 2016

you’re welcome

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'store' of undefined in Javascript class
Cannot read property 'store' of undefined. I'm clearly missing an import here but unclear as to how I'd import store .
Read more >
Cannot read property 'store' of undefined · Issue #137 - GitHub
Hello,. I'm getting the following error at the time of SSR. TypeError: Cannot read property 'store' of undefined at Object.
Read more >
I'm getting Cannot read property '$store' of undefined
i'm getting this error TypeError: Cannot read property '$store' of undefined on my component <template> <span @click="requestEmbedManager" ...
Read more >
cannot read properties of null (reading 'store') - You.com
To solve the "Cannot read property 'value' of null" error, make sure that the JS script tag is placed at the bottom of...
Read more >
How to Read React Errors (fix 'Cannot read property of ...
This error usually means you're trying to use .map on an array, but that array isn't defined yet. That's often because the array...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found