Angular 6: pass id from one component to another component
My situation:
I have a Login Component ,when i will login , i will get response from API like
{
code: 200,
id: 4,
msg: "success",
user: "Sourav"
}
I want to send this id to Candidate component ,cv Details Component and Key skills component .
My code
MyCommonService:
import{ Injectable } from'@angular/core';
@Injectable({
providedIn: 'root',
})
export class CommonUserService {
public userId;
constructor() {}
setUserLoggedIn(Id) {
this.userId = Id;
console.log(this.userId);
}
getUserLoggedIn() {
console.log(this.userId);
return this.userId;
}
}
LoginComponent
Here I am setting the id using common service
login() {
if (this.seekerlogin.code == '200') {
this.commonuserservice.setUserLoggedIn(this.seekerlogin.id);
}
}
Candiadate Component
Here it's showing id is Undefined
submit(){
let id = this.commonuserservice.getUserLoggedIn(); // Here showing id is
Undefined
let name = this.name;
this.companydetailssevice.candidateServiceMethod(id,name)
.subscribe(
data => {
this.ResponseVariable= data;
if(this.ResponseVariable.code =='200'){
this.router.navigate(['key_skill']);
}
},
error => alert(error),
() => console.log(this.ResponseVariable)
);
}
please help me where i am doing wrong or tell me any other solutions
angular
add a comment |
My situation:
I have a Login Component ,when i will login , i will get response from API like
{
code: 200,
id: 4,
msg: "success",
user: "Sourav"
}
I want to send this id to Candidate component ,cv Details Component and Key skills component .
My code
MyCommonService:
import{ Injectable } from'@angular/core';
@Injectable({
providedIn: 'root',
})
export class CommonUserService {
public userId;
constructor() {}
setUserLoggedIn(Id) {
this.userId = Id;
console.log(this.userId);
}
getUserLoggedIn() {
console.log(this.userId);
return this.userId;
}
}
LoginComponent
Here I am setting the id using common service
login() {
if (this.seekerlogin.code == '200') {
this.commonuserservice.setUserLoggedIn(this.seekerlogin.id);
}
}
Candiadate Component
Here it's showing id is Undefined
submit(){
let id = this.commonuserservice.getUserLoggedIn(); // Here showing id is
Undefined
let name = this.name;
this.companydetailssevice.candidateServiceMethod(id,name)
.subscribe(
data => {
this.ResponseVariable= data;
if(this.ResponseVariable.code =='200'){
this.router.navigate(['key_skill']);
}
},
error => alert(error),
() => console.log(this.ResponseVariable)
);
}
please help me where i am doing wrong or tell me any other solutions
angular
Welcome. Do you need to retrieve the value on the same page/request as you stored it, or on future ones as well? Also, do you work with a server (which you make HTTP requests to), or you just have an Angular client? If you don't work with a server and you need to store the login info for future requests, take a look at sessionStorage (or localStorage).
– Jeto
Nov 23 at 8:57
For all component interactions, this page of the docs is excellent - angular.io/guide/component-interaction
– HockeyJ
Nov 23 at 9:00
It would be great if you could provide a Minimal, Complete, and Verifiable example. You can use StackBlitz to create one.
– SiddAjmera
Nov 23 at 9:01
ya using localStorageage i can do this but is it secure ?@Jeto
– lpd
Nov 23 at 9:02
Your code looks good, but please put this code in js fiddel or Stcakblitz.
– Himanshu Shekhar
Nov 23 at 9:04
add a comment |
My situation:
I have a Login Component ,when i will login , i will get response from API like
{
code: 200,
id: 4,
msg: "success",
user: "Sourav"
}
I want to send this id to Candidate component ,cv Details Component and Key skills component .
My code
MyCommonService:
import{ Injectable } from'@angular/core';
@Injectable({
providedIn: 'root',
})
export class CommonUserService {
public userId;
constructor() {}
setUserLoggedIn(Id) {
this.userId = Id;
console.log(this.userId);
}
getUserLoggedIn() {
console.log(this.userId);
return this.userId;
}
}
LoginComponent
Here I am setting the id using common service
login() {
if (this.seekerlogin.code == '200') {
this.commonuserservice.setUserLoggedIn(this.seekerlogin.id);
}
}
Candiadate Component
Here it's showing id is Undefined
submit(){
let id = this.commonuserservice.getUserLoggedIn(); // Here showing id is
Undefined
let name = this.name;
this.companydetailssevice.candidateServiceMethod(id,name)
.subscribe(
data => {
this.ResponseVariable= data;
if(this.ResponseVariable.code =='200'){
this.router.navigate(['key_skill']);
}
},
error => alert(error),
() => console.log(this.ResponseVariable)
);
}
please help me where i am doing wrong or tell me any other solutions
angular
My situation:
I have a Login Component ,when i will login , i will get response from API like
{
code: 200,
id: 4,
msg: "success",
user: "Sourav"
}
I want to send this id to Candidate component ,cv Details Component and Key skills component .
My code
MyCommonService:
import{ Injectable } from'@angular/core';
@Injectable({
providedIn: 'root',
})
export class CommonUserService {
public userId;
constructor() {}
setUserLoggedIn(Id) {
this.userId = Id;
console.log(this.userId);
}
getUserLoggedIn() {
console.log(this.userId);
return this.userId;
}
}
LoginComponent
Here I am setting the id using common service
login() {
if (this.seekerlogin.code == '200') {
this.commonuserservice.setUserLoggedIn(this.seekerlogin.id);
}
}
Candiadate Component
Here it's showing id is Undefined
submit(){
let id = this.commonuserservice.getUserLoggedIn(); // Here showing id is
Undefined
let name = this.name;
this.companydetailssevice.candidateServiceMethod(id,name)
.subscribe(
data => {
this.ResponseVariable= data;
if(this.ResponseVariable.code =='200'){
this.router.navigate(['key_skill']);
}
},
error => alert(error),
() => console.log(this.ResponseVariable)
);
}
please help me where i am doing wrong or tell me any other solutions
angular
angular
edited Nov 23 at 9:38
asked Nov 23 at 8:54
lpd
206
206
Welcome. Do you need to retrieve the value on the same page/request as you stored it, or on future ones as well? Also, do you work with a server (which you make HTTP requests to), or you just have an Angular client? If you don't work with a server and you need to store the login info for future requests, take a look at sessionStorage (or localStorage).
– Jeto
Nov 23 at 8:57
For all component interactions, this page of the docs is excellent - angular.io/guide/component-interaction
– HockeyJ
Nov 23 at 9:00
It would be great if you could provide a Minimal, Complete, and Verifiable example. You can use StackBlitz to create one.
– SiddAjmera
Nov 23 at 9:01
ya using localStorageage i can do this but is it secure ?@Jeto
– lpd
Nov 23 at 9:02
Your code looks good, but please put this code in js fiddel or Stcakblitz.
– Himanshu Shekhar
Nov 23 at 9:04
add a comment |
Welcome. Do you need to retrieve the value on the same page/request as you stored it, or on future ones as well? Also, do you work with a server (which you make HTTP requests to), or you just have an Angular client? If you don't work with a server and you need to store the login info for future requests, take a look at sessionStorage (or localStorage).
– Jeto
Nov 23 at 8:57
For all component interactions, this page of the docs is excellent - angular.io/guide/component-interaction
– HockeyJ
Nov 23 at 9:00
It would be great if you could provide a Minimal, Complete, and Verifiable example. You can use StackBlitz to create one.
– SiddAjmera
Nov 23 at 9:01
ya using localStorageage i can do this but is it secure ?@Jeto
– lpd
Nov 23 at 9:02
Your code looks good, but please put this code in js fiddel or Stcakblitz.
– Himanshu Shekhar
Nov 23 at 9:04
Welcome. Do you need to retrieve the value on the same page/request as you stored it, or on future ones as well? Also, do you work with a server (which you make HTTP requests to), or you just have an Angular client? If you don't work with a server and you need to store the login info for future requests, take a look at sessionStorage (or localStorage).
– Jeto
Nov 23 at 8:57
Welcome. Do you need to retrieve the value on the same page/request as you stored it, or on future ones as well? Also, do you work with a server (which you make HTTP requests to), or you just have an Angular client? If you don't work with a server and you need to store the login info for future requests, take a look at sessionStorage (or localStorage).
– Jeto
Nov 23 at 8:57
For all component interactions, this page of the docs is excellent - angular.io/guide/component-interaction
– HockeyJ
Nov 23 at 9:00
For all component interactions, this page of the docs is excellent - angular.io/guide/component-interaction
– HockeyJ
Nov 23 at 9:00
It would be great if you could provide a Minimal, Complete, and Verifiable example. You can use StackBlitz to create one.
– SiddAjmera
Nov 23 at 9:01
It would be great if you could provide a Minimal, Complete, and Verifiable example. You can use StackBlitz to create one.
– SiddAjmera
Nov 23 at 9:01
ya using localStorageage i can do this but is it secure ?@Jeto
– lpd
Nov 23 at 9:02
ya using localStorageage i can do this but is it secure ?@Jeto
– lpd
Nov 23 at 9:02
Your code looks good, but please put this code in js fiddel or Stcakblitz.
– Himanshu Shekhar
Nov 23 at 9:04
Your code looks good, but please put this code in js fiddel or Stcakblitz.
– Himanshu Shekhar
Nov 23 at 9:04
add a comment |
2 Answers
2
active
oldest
votes
We have multiple ways to share data from one controller to another.
But in simple way you can go with localStorage.
Please check sample code.
Step 1: Alter your service
import { Injectable } from '@angular/core';
@Injectable()
export class CommonUserService {
constructor() { }
//State Management
setSession(key: string, value: any): void {
//sessionStorage.setItem(key, JSON.stringify(value));
localStorage.setItem(key, JSON.stringify(value));
}
getSession(key: string): any {
if (typeof window !== 'undefined') {
//let retrievedObject = sessionStorage.getItem(key) as string;
let retrievedObject = localStorage.getItem(key) as string;
return retrievedObject;
}
}
clearSession(): void {
localStorage.clear();
}
}
Step 2: Set and Get session value.
this._commonUserService.setSession('UserId', UserId);
let userId= this._commonUserService.getSession('UserId');
If it's not needed to save the value for the usage of other tabs usesessionStorage
for one tab only.
– Swoox
Nov 23 at 10:03
add a comment |
It should work. What you're doing is the correct way to go. Just make sure you're running a single instance of CommonUserService
in all the components. Make sure you have added CommonUserService
to the providers
array in a module and not in individual components.
import{ Injectable } from'@angular/core';
@Injectable()
export class CommonUserService {
public userId;
constructor() {}
setUserLoggedIn(Id) {
this.userId = Id;
console.log(this.userId);
}
getUserLoggedIn() {
console.log(this.userId);
return this.userId;
}
}
Then in your module
@NgModule({
declarations: [
AppComponent,
ItemDirective
],
imports: [
],
providers: [CommonUserService],
bootstrap: [AppComponent]
})
export class AppModule { }
And your compoenents
@Component({
selector: 'app-bank-account',
template: `
Bank Name: {{ bankName }}
Account Id: {{ id }}
`
})
export class BankAccountComponent {
bankName: string|null = null;
id: string|null = null;
constructor(private commonService: CommonUserService){
}
}
please check i have edited my code but still it's showing id is Undefined.
– lpd
Nov 23 at 9:40
It's hard to say what the issue is. Can you post your code on Stackblitz (stackblitz.com/fork/angular)? I'll take a look.
– Manish Gharat
Nov 23 at 15:30
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2f53443371%2fangular-6-pass-id-from-one-component-to-another-component%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
We have multiple ways to share data from one controller to another.
But in simple way you can go with localStorage.
Please check sample code.
Step 1: Alter your service
import { Injectable } from '@angular/core';
@Injectable()
export class CommonUserService {
constructor() { }
//State Management
setSession(key: string, value: any): void {
//sessionStorage.setItem(key, JSON.stringify(value));
localStorage.setItem(key, JSON.stringify(value));
}
getSession(key: string): any {
if (typeof window !== 'undefined') {
//let retrievedObject = sessionStorage.getItem(key) as string;
let retrievedObject = localStorage.getItem(key) as string;
return retrievedObject;
}
}
clearSession(): void {
localStorage.clear();
}
}
Step 2: Set and Get session value.
this._commonUserService.setSession('UserId', UserId);
let userId= this._commonUserService.getSession('UserId');
If it's not needed to save the value for the usage of other tabs usesessionStorage
for one tab only.
– Swoox
Nov 23 at 10:03
add a comment |
We have multiple ways to share data from one controller to another.
But in simple way you can go with localStorage.
Please check sample code.
Step 1: Alter your service
import { Injectable } from '@angular/core';
@Injectable()
export class CommonUserService {
constructor() { }
//State Management
setSession(key: string, value: any): void {
//sessionStorage.setItem(key, JSON.stringify(value));
localStorage.setItem(key, JSON.stringify(value));
}
getSession(key: string): any {
if (typeof window !== 'undefined') {
//let retrievedObject = sessionStorage.getItem(key) as string;
let retrievedObject = localStorage.getItem(key) as string;
return retrievedObject;
}
}
clearSession(): void {
localStorage.clear();
}
}
Step 2: Set and Get session value.
this._commonUserService.setSession('UserId', UserId);
let userId= this._commonUserService.getSession('UserId');
If it's not needed to save the value for the usage of other tabs usesessionStorage
for one tab only.
– Swoox
Nov 23 at 10:03
add a comment |
We have multiple ways to share data from one controller to another.
But in simple way you can go with localStorage.
Please check sample code.
Step 1: Alter your service
import { Injectable } from '@angular/core';
@Injectable()
export class CommonUserService {
constructor() { }
//State Management
setSession(key: string, value: any): void {
//sessionStorage.setItem(key, JSON.stringify(value));
localStorage.setItem(key, JSON.stringify(value));
}
getSession(key: string): any {
if (typeof window !== 'undefined') {
//let retrievedObject = sessionStorage.getItem(key) as string;
let retrievedObject = localStorage.getItem(key) as string;
return retrievedObject;
}
}
clearSession(): void {
localStorage.clear();
}
}
Step 2: Set and Get session value.
this._commonUserService.setSession('UserId', UserId);
let userId= this._commonUserService.getSession('UserId');
We have multiple ways to share data from one controller to another.
But in simple way you can go with localStorage.
Please check sample code.
Step 1: Alter your service
import { Injectable } from '@angular/core';
@Injectable()
export class CommonUserService {
constructor() { }
//State Management
setSession(key: string, value: any): void {
//sessionStorage.setItem(key, JSON.stringify(value));
localStorage.setItem(key, JSON.stringify(value));
}
getSession(key: string): any {
if (typeof window !== 'undefined') {
//let retrievedObject = sessionStorage.getItem(key) as string;
let retrievedObject = localStorage.getItem(key) as string;
return retrievedObject;
}
}
clearSession(): void {
localStorage.clear();
}
}
Step 2: Set and Get session value.
this._commonUserService.setSession('UserId', UserId);
let userId= this._commonUserService.getSession('UserId');
edited Nov 23 at 9:47
answered Nov 23 at 9:09
Sanjay Katiyar
38518
38518
If it's not needed to save the value for the usage of other tabs usesessionStorage
for one tab only.
– Swoox
Nov 23 at 10:03
add a comment |
If it's not needed to save the value for the usage of other tabs usesessionStorage
for one tab only.
– Swoox
Nov 23 at 10:03
If it's not needed to save the value for the usage of other tabs use
sessionStorage
for one tab only.– Swoox
Nov 23 at 10:03
If it's not needed to save the value for the usage of other tabs use
sessionStorage
for one tab only.– Swoox
Nov 23 at 10:03
add a comment |
It should work. What you're doing is the correct way to go. Just make sure you're running a single instance of CommonUserService
in all the components. Make sure you have added CommonUserService
to the providers
array in a module and not in individual components.
import{ Injectable } from'@angular/core';
@Injectable()
export class CommonUserService {
public userId;
constructor() {}
setUserLoggedIn(Id) {
this.userId = Id;
console.log(this.userId);
}
getUserLoggedIn() {
console.log(this.userId);
return this.userId;
}
}
Then in your module
@NgModule({
declarations: [
AppComponent,
ItemDirective
],
imports: [
],
providers: [CommonUserService],
bootstrap: [AppComponent]
})
export class AppModule { }
And your compoenents
@Component({
selector: 'app-bank-account',
template: `
Bank Name: {{ bankName }}
Account Id: {{ id }}
`
})
export class BankAccountComponent {
bankName: string|null = null;
id: string|null = null;
constructor(private commonService: CommonUserService){
}
}
please check i have edited my code but still it's showing id is Undefined.
– lpd
Nov 23 at 9:40
It's hard to say what the issue is. Can you post your code on Stackblitz (stackblitz.com/fork/angular)? I'll take a look.
– Manish Gharat
Nov 23 at 15:30
add a comment |
It should work. What you're doing is the correct way to go. Just make sure you're running a single instance of CommonUserService
in all the components. Make sure you have added CommonUserService
to the providers
array in a module and not in individual components.
import{ Injectable } from'@angular/core';
@Injectable()
export class CommonUserService {
public userId;
constructor() {}
setUserLoggedIn(Id) {
this.userId = Id;
console.log(this.userId);
}
getUserLoggedIn() {
console.log(this.userId);
return this.userId;
}
}
Then in your module
@NgModule({
declarations: [
AppComponent,
ItemDirective
],
imports: [
],
providers: [CommonUserService],
bootstrap: [AppComponent]
})
export class AppModule { }
And your compoenents
@Component({
selector: 'app-bank-account',
template: `
Bank Name: {{ bankName }}
Account Id: {{ id }}
`
})
export class BankAccountComponent {
bankName: string|null = null;
id: string|null = null;
constructor(private commonService: CommonUserService){
}
}
please check i have edited my code but still it's showing id is Undefined.
– lpd
Nov 23 at 9:40
It's hard to say what the issue is. Can you post your code on Stackblitz (stackblitz.com/fork/angular)? I'll take a look.
– Manish Gharat
Nov 23 at 15:30
add a comment |
It should work. What you're doing is the correct way to go. Just make sure you're running a single instance of CommonUserService
in all the components. Make sure you have added CommonUserService
to the providers
array in a module and not in individual components.
import{ Injectable } from'@angular/core';
@Injectable()
export class CommonUserService {
public userId;
constructor() {}
setUserLoggedIn(Id) {
this.userId = Id;
console.log(this.userId);
}
getUserLoggedIn() {
console.log(this.userId);
return this.userId;
}
}
Then in your module
@NgModule({
declarations: [
AppComponent,
ItemDirective
],
imports: [
],
providers: [CommonUserService],
bootstrap: [AppComponent]
})
export class AppModule { }
And your compoenents
@Component({
selector: 'app-bank-account',
template: `
Bank Name: {{ bankName }}
Account Id: {{ id }}
`
})
export class BankAccountComponent {
bankName: string|null = null;
id: string|null = null;
constructor(private commonService: CommonUserService){
}
}
It should work. What you're doing is the correct way to go. Just make sure you're running a single instance of CommonUserService
in all the components. Make sure you have added CommonUserService
to the providers
array in a module and not in individual components.
import{ Injectable } from'@angular/core';
@Injectable()
export class CommonUserService {
public userId;
constructor() {}
setUserLoggedIn(Id) {
this.userId = Id;
console.log(this.userId);
}
getUserLoggedIn() {
console.log(this.userId);
return this.userId;
}
}
Then in your module
@NgModule({
declarations: [
AppComponent,
ItemDirective
],
imports: [
],
providers: [CommonUserService],
bootstrap: [AppComponent]
})
export class AppModule { }
And your compoenents
@Component({
selector: 'app-bank-account',
template: `
Bank Name: {{ bankName }}
Account Id: {{ id }}
`
})
export class BankAccountComponent {
bankName: string|null = null;
id: string|null = null;
constructor(private commonService: CommonUserService){
}
}
import{ Injectable } from'@angular/core';
@Injectable()
export class CommonUserService {
public userId;
constructor() {}
setUserLoggedIn(Id) {
this.userId = Id;
console.log(this.userId);
}
getUserLoggedIn() {
console.log(this.userId);
return this.userId;
}
}
import{ Injectable } from'@angular/core';
@Injectable()
export class CommonUserService {
public userId;
constructor() {}
setUserLoggedIn(Id) {
this.userId = Id;
console.log(this.userId);
}
getUserLoggedIn() {
console.log(this.userId);
return this.userId;
}
}
@NgModule({
declarations: [
AppComponent,
ItemDirective
],
imports: [
],
providers: [CommonUserService],
bootstrap: [AppComponent]
})
export class AppModule { }
@NgModule({
declarations: [
AppComponent,
ItemDirective
],
imports: [
],
providers: [CommonUserService],
bootstrap: [AppComponent]
})
export class AppModule { }
@Component({
selector: 'app-bank-account',
template: `
Bank Name: {{ bankName }}
Account Id: {{ id }}
`
})
export class BankAccountComponent {
bankName: string|null = null;
id: string|null = null;
constructor(private commonService: CommonUserService){
}
}
@Component({
selector: 'app-bank-account',
template: `
Bank Name: {{ bankName }}
Account Id: {{ id }}
`
})
export class BankAccountComponent {
bankName: string|null = null;
id: string|null = null;
constructor(private commonService: CommonUserService){
}
}
answered Nov 23 at 9:05
Manish Gharat
31618
31618
please check i have edited my code but still it's showing id is Undefined.
– lpd
Nov 23 at 9:40
It's hard to say what the issue is. Can you post your code on Stackblitz (stackblitz.com/fork/angular)? I'll take a look.
– Manish Gharat
Nov 23 at 15:30
add a comment |
please check i have edited my code but still it's showing id is Undefined.
– lpd
Nov 23 at 9:40
It's hard to say what the issue is. Can you post your code on Stackblitz (stackblitz.com/fork/angular)? I'll take a look.
– Manish Gharat
Nov 23 at 15:30
please check i have edited my code but still it's showing id is Undefined.
– lpd
Nov 23 at 9:40
please check i have edited my code but still it's showing id is Undefined.
– lpd
Nov 23 at 9:40
It's hard to say what the issue is. Can you post your code on Stackblitz (stackblitz.com/fork/angular)? I'll take a look.
– Manish Gharat
Nov 23 at 15:30
It's hard to say what the issue is. Can you post your code on Stackblitz (stackblitz.com/fork/angular)? I'll take a look.
– Manish Gharat
Nov 23 at 15:30
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f53443371%2fangular-6-pass-id-from-one-component-to-another-component%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
Welcome. Do you need to retrieve the value on the same page/request as you stored it, or on future ones as well? Also, do you work with a server (which you make HTTP requests to), or you just have an Angular client? If you don't work with a server and you need to store the login info for future requests, take a look at sessionStorage (or localStorage).
– Jeto
Nov 23 at 8:57
For all component interactions, this page of the docs is excellent - angular.io/guide/component-interaction
– HockeyJ
Nov 23 at 9:00
It would be great if you could provide a Minimal, Complete, and Verifiable example. You can use StackBlitz to create one.
– SiddAjmera
Nov 23 at 9:01
ya using localStorageage i can do this but is it secure ?@Jeto
– lpd
Nov 23 at 9:02
Your code looks good, but please put this code in js fiddel or Stcakblitz.
– Himanshu Shekhar
Nov 23 at 9:04