Angular/NGXS sample code - cannot get reference of the parameter input
up vote
1
down vote
favorite
I'm trying to implement the login as mentioned here.
https://ngxs.gitbook.io/ngxs/recipes/authentication
@Action(Login)
login( patchState : StateContext<AuthStateModel>, payload: username : Login)
return this.authService.login(payload).pipe(tap((result: token: string ) =>
patchState( token, username );
))
But I'm unable to get the reference of 'payload' as shown in the sample, instead I get the following error. Any help appreciated ! I also wanted to know what ' payload: username ' would mean in the input parameters of the function.
angular angular6 rxjs6 ngxs
add a comment |
up vote
1
down vote
favorite
I'm trying to implement the login as mentioned here.
https://ngxs.gitbook.io/ngxs/recipes/authentication
@Action(Login)
login( patchState : StateContext<AuthStateModel>, payload: username : Login)
return this.authService.login(payload).pipe(tap((result: token: string ) =>
patchState( token, username );
))
But I'm unable to get the reference of 'payload' as shown in the sample, instead I get the following error. Any help appreciated ! I also wanted to know what ' payload: username ' would mean in the input parameters of the function.
angular angular6 rxjs6 ngxs
Aby, did my answer shed light on your issue? I've explained the object destructuring, identified the error, and showed the solution. Did you get past this issue?
– Rafael
Nov 10 at 3:06
Yes, absolutely Rafael. Thanks for your time !! keep up the good job.
– Aby
Nov 14 at 9:14
Awesome, I'm glad to hear that. The fix was merged in #653
– Rafael
Nov 14 at 16:35
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm trying to implement the login as mentioned here.
https://ngxs.gitbook.io/ngxs/recipes/authentication
@Action(Login)
login( patchState : StateContext<AuthStateModel>, payload: username : Login)
return this.authService.login(payload).pipe(tap((result: token: string ) =>
patchState( token, username );
))
But I'm unable to get the reference of 'payload' as shown in the sample, instead I get the following error. Any help appreciated ! I also wanted to know what ' payload: username ' would mean in the input parameters of the function.
angular angular6 rxjs6 ngxs
I'm trying to implement the login as mentioned here.
https://ngxs.gitbook.io/ngxs/recipes/authentication
@Action(Login)
login( patchState : StateContext<AuthStateModel>, payload: username : Login)
return this.authService.login(payload).pipe(tap((result: token: string ) =>
patchState( token, username );
))
But I'm unable to get the reference of 'payload' as shown in the sample, instead I get the following error. Any help appreciated ! I also wanted to know what ' payload: username ' would mean in the input parameters of the function.
angular angular6 rxjs6 ngxs
angular angular6 rxjs6 ngxs
asked Nov 9 at 23:40
Aby
1,6461814
1,6461814
Aby, did my answer shed light on your issue? I've explained the object destructuring, identified the error, and showed the solution. Did you get past this issue?
– Rafael
Nov 10 at 3:06
Yes, absolutely Rafael. Thanks for your time !! keep up the good job.
– Aby
Nov 14 at 9:14
Awesome, I'm glad to hear that. The fix was merged in #653
– Rafael
Nov 14 at 16:35
add a comment |
Aby, did my answer shed light on your issue? I've explained the object destructuring, identified the error, and showed the solution. Did you get past this issue?
– Rafael
Nov 10 at 3:06
Yes, absolutely Rafael. Thanks for your time !! keep up the good job.
– Aby
Nov 14 at 9:14
Awesome, I'm glad to hear that. The fix was merged in #653
– Rafael
Nov 14 at 16:35
Aby, did my answer shed light on your issue? I've explained the object destructuring, identified the error, and showed the solution. Did you get past this issue?
– Rafael
Nov 10 at 3:06
Aby, did my answer shed light on your issue? I've explained the object destructuring, identified the error, and showed the solution. Did you get past this issue?
– Rafael
Nov 10 at 3:06
Yes, absolutely Rafael. Thanks for your time !! keep up the good job.
– Aby
Nov 14 at 9:14
Yes, absolutely Rafael. Thanks for your time !! keep up the good job.
– Aby
Nov 14 at 9:14
Awesome, I'm glad to hear that. The fix was merged in #653
– Rafael
Nov 14 at 16:35
Awesome, I'm glad to hear that. The fix was merged in #653
– Rafael
Nov 14 at 16:35
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
This is an error in the documentation.
Look here:
export class Login
static readonly type = '[Auth] Login';
constructor(public payload: username: string, password: string )
and here:
login( patchState : StateContext<AuthStateModel>, payload: username : Login) {
This is a destructure mistake and needs to be:
@Action(Login)
login( patchState : StateContext<AuthStateModel>, payload : Login)
return this.authService.login(payload).pipe(tap((result: token: string ) =>
patchState( token, username: payload.username );
))
This destructures Login's payload
and then reference username
via payload.username
.
Credentials are sent upstream and a token is returned downstream. The AuthStateModel is patched via the StateContext.
Git Blame authentication.md
What Is Destructuring?
payload: username
is Destructuring assignment
. In the context of a function parameter, it means, "in this object, I am interested in these properties." Looking at login()
, it means, "I am only interested in username
(which is wrong as state above).
I hope this helps!
UPDATE:
This fix has been merged in #653.
Just to clarify:
let a = payload: username: first: 'rafael', last: 'cepeda' ;
let payload: username = a;//unwraps payload.username
console.log(username);//works
console.log(payload);//error
Fix:
let a = payload: username: first: 'rafael', last: 'cepeda' ;
let payload = a;//unwraps payload
console.log(payload.username);//works
console.log(payload);//works
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
This is an error in the documentation.
Look here:
export class Login
static readonly type = '[Auth] Login';
constructor(public payload: username: string, password: string )
and here:
login( patchState : StateContext<AuthStateModel>, payload: username : Login) {
This is a destructure mistake and needs to be:
@Action(Login)
login( patchState : StateContext<AuthStateModel>, payload : Login)
return this.authService.login(payload).pipe(tap((result: token: string ) =>
patchState( token, username: payload.username );
))
This destructures Login's payload
and then reference username
via payload.username
.
Credentials are sent upstream and a token is returned downstream. The AuthStateModel is patched via the StateContext.
Git Blame authentication.md
What Is Destructuring?
payload: username
is Destructuring assignment
. In the context of a function parameter, it means, "in this object, I am interested in these properties." Looking at login()
, it means, "I am only interested in username
(which is wrong as state above).
I hope this helps!
UPDATE:
This fix has been merged in #653.
Just to clarify:
let a = payload: username: first: 'rafael', last: 'cepeda' ;
let payload: username = a;//unwraps payload.username
console.log(username);//works
console.log(payload);//error
Fix:
let a = payload: username: first: 'rafael', last: 'cepeda' ;
let payload = a;//unwraps payload
console.log(payload.username);//works
console.log(payload);//works
add a comment |
up vote
1
down vote
accepted
This is an error in the documentation.
Look here:
export class Login
static readonly type = '[Auth] Login';
constructor(public payload: username: string, password: string )
and here:
login( patchState : StateContext<AuthStateModel>, payload: username : Login) {
This is a destructure mistake and needs to be:
@Action(Login)
login( patchState : StateContext<AuthStateModel>, payload : Login)
return this.authService.login(payload).pipe(tap((result: token: string ) =>
patchState( token, username: payload.username );
))
This destructures Login's payload
and then reference username
via payload.username
.
Credentials are sent upstream and a token is returned downstream. The AuthStateModel is patched via the StateContext.
Git Blame authentication.md
What Is Destructuring?
payload: username
is Destructuring assignment
. In the context of a function parameter, it means, "in this object, I am interested in these properties." Looking at login()
, it means, "I am only interested in username
(which is wrong as state above).
I hope this helps!
UPDATE:
This fix has been merged in #653.
Just to clarify:
let a = payload: username: first: 'rafael', last: 'cepeda' ;
let payload: username = a;//unwraps payload.username
console.log(username);//works
console.log(payload);//error
Fix:
let a = payload: username: first: 'rafael', last: 'cepeda' ;
let payload = a;//unwraps payload
console.log(payload.username);//works
console.log(payload);//works
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
This is an error in the documentation.
Look here:
export class Login
static readonly type = '[Auth] Login';
constructor(public payload: username: string, password: string )
and here:
login( patchState : StateContext<AuthStateModel>, payload: username : Login) {
This is a destructure mistake and needs to be:
@Action(Login)
login( patchState : StateContext<AuthStateModel>, payload : Login)
return this.authService.login(payload).pipe(tap((result: token: string ) =>
patchState( token, username: payload.username );
))
This destructures Login's payload
and then reference username
via payload.username
.
Credentials are sent upstream and a token is returned downstream. The AuthStateModel is patched via the StateContext.
Git Blame authentication.md
What Is Destructuring?
payload: username
is Destructuring assignment
. In the context of a function parameter, it means, "in this object, I am interested in these properties." Looking at login()
, it means, "I am only interested in username
(which is wrong as state above).
I hope this helps!
UPDATE:
This fix has been merged in #653.
Just to clarify:
let a = payload: username: first: 'rafael', last: 'cepeda' ;
let payload: username = a;//unwraps payload.username
console.log(username);//works
console.log(payload);//error
Fix:
let a = payload: username: first: 'rafael', last: 'cepeda' ;
let payload = a;//unwraps payload
console.log(payload.username);//works
console.log(payload);//works
This is an error in the documentation.
Look here:
export class Login
static readonly type = '[Auth] Login';
constructor(public payload: username: string, password: string )
and here:
login( patchState : StateContext<AuthStateModel>, payload: username : Login) {
This is a destructure mistake and needs to be:
@Action(Login)
login( patchState : StateContext<AuthStateModel>, payload : Login)
return this.authService.login(payload).pipe(tap((result: token: string ) =>
patchState( token, username: payload.username );
))
This destructures Login's payload
and then reference username
via payload.username
.
Credentials are sent upstream and a token is returned downstream. The AuthStateModel is patched via the StateContext.
Git Blame authentication.md
What Is Destructuring?
payload: username
is Destructuring assignment
. In the context of a function parameter, it means, "in this object, I am interested in these properties." Looking at login()
, it means, "I am only interested in username
(which is wrong as state above).
I hope this helps!
UPDATE:
This fix has been merged in #653.
Just to clarify:
let a = payload: username: first: 'rafael', last: 'cepeda' ;
let payload: username = a;//unwraps payload.username
console.log(username);//works
console.log(payload);//error
Fix:
let a = payload: username: first: 'rafael', last: 'cepeda' ;
let payload = a;//unwraps payload
console.log(payload.username);//works
console.log(payload);//works
let a = payload: username: first: 'rafael', last: 'cepeda' ;
let payload: username = a;//unwraps payload.username
console.log(username);//works
console.log(payload);//error
let a = payload: username: first: 'rafael', last: 'cepeda' ;
let payload: username = a;//unwraps payload.username
console.log(username);//works
console.log(payload);//error
let a = payload: username: first: 'rafael', last: 'cepeda' ;
let payload = a;//unwraps payload
console.log(payload.username);//works
console.log(payload);//works
let a = payload: username: first: 'rafael', last: 'cepeda' ;
let payload = a;//unwraps payload
console.log(payload.username);//works
console.log(payload);//works
edited Nov 14 at 16:34
answered Nov 9 at 23:50
Rafael
4,30872037
4,30872037
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53234647%2fangular-ngxs-sample-code-cannot-get-reference-of-the-parameter-input%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Aby, did my answer shed light on your issue? I've explained the object destructuring, identified the error, and showed the solution. Did you get past this issue?
– Rafael
Nov 10 at 3:06
Yes, absolutely Rafael. Thanks for your time !! keep up the good job.
– Aby
Nov 14 at 9:14
Awesome, I'm glad to hear that. The fix was merged in #653
– Rafael
Nov 14 at 16:35