wangzixi-diablo / Spartacus-learning

record questions raised during my study
0 stars 1 forks source link

one question regarding B2BUserService #11

Open wangzixi-diablo opened 3 years ago

wangzixi-diablo commented 3 years ago

This issue is for discussion in this StackOverflow question:https://stackoverflow.com/questions/66458798/how-can-i-detect-current-users-user-group-in-spartacus

clipboard1

In order to test it, I add the following source code in AppModule's constructor:

constructor(b2b: B2BUserService){
    const result = b2b.getUserGroups('ab3f7a08-690a-4616-b1fe-4f0847fcb79f', {
      pageSize: 100
    });

    result.subscribe((data) => console.log('Ethan: ' , data));
  }
clipboard2

I expect the user group data is printed.

Unfortunately I meet with this error message:

ERROR TypeError: Cannot read property 'b2bUser' of undefined

clipboard3

callstack:

clipboard4

Do I need to call some other method to "initialize" the state before I access it?