Angular - how to use data from subcribe or map and set in object after post request
After post request, this return me some data and I don't know how I can use this data and set to object class, or any object, or just print in console log.
Console log always write undefined object.
onSubmit()
{
this.http.post('some/api',
JSON.stringify({
user_name: this.login_form.value.user_name,
password: this.login_form.value.password
}),
this.options
)
.subscribe(data => {
this.getUserData = data[0];
this.user = {
Ime: data['Ime'],
Prezime: data['Prezime'],
Username: data['Username'],
Sifra: data['Sifra'],
Broj_telefona: data['Broj_telefona'],
jmbg: data['jmbg'],
Nivo: data['Nivo']
}
});
console.log(this.user);
console.log(this.getUserData);
}
this is class User
export class User {
constructor(
Ime: any,
Prezime: any,
Username: any,
Sifra: any,
Broj_telefona: any,
jmbg: any,
Nivo: any
) {}
}
angular
add a comment |
After post request, this return me some data and I don't know how I can use this data and set to object class, or any object, or just print in console log.
Console log always write undefined object.
onSubmit()
{
this.http.post('some/api',
JSON.stringify({
user_name: this.login_form.value.user_name,
password: this.login_form.value.password
}),
this.options
)
.subscribe(data => {
this.getUserData = data[0];
this.user = {
Ime: data['Ime'],
Prezime: data['Prezime'],
Username: data['Username'],
Sifra: data['Sifra'],
Broj_telefona: data['Broj_telefona'],
jmbg: data['jmbg'],
Nivo: data['Nivo']
}
});
console.log(this.user);
console.log(this.getUserData);
}
this is class User
export class User {
constructor(
Ime: any,
Prezime: any,
Username: any,
Sifra: any,
Broj_telefona: any,
jmbg: any,
Nivo: any
) {}
}
angular
add a comment |
After post request, this return me some data and I don't know how I can use this data and set to object class, or any object, or just print in console log.
Console log always write undefined object.
onSubmit()
{
this.http.post('some/api',
JSON.stringify({
user_name: this.login_form.value.user_name,
password: this.login_form.value.password
}),
this.options
)
.subscribe(data => {
this.getUserData = data[0];
this.user = {
Ime: data['Ime'],
Prezime: data['Prezime'],
Username: data['Username'],
Sifra: data['Sifra'],
Broj_telefona: data['Broj_telefona'],
jmbg: data['jmbg'],
Nivo: data['Nivo']
}
});
console.log(this.user);
console.log(this.getUserData);
}
this is class User
export class User {
constructor(
Ime: any,
Prezime: any,
Username: any,
Sifra: any,
Broj_telefona: any,
jmbg: any,
Nivo: any
) {}
}
angular
After post request, this return me some data and I don't know how I can use this data and set to object class, or any object, or just print in console log.
Console log always write undefined object.
onSubmit()
{
this.http.post('some/api',
JSON.stringify({
user_name: this.login_form.value.user_name,
password: this.login_form.value.password
}),
this.options
)
.subscribe(data => {
this.getUserData = data[0];
this.user = {
Ime: data['Ime'],
Prezime: data['Prezime'],
Username: data['Username'],
Sifra: data['Sifra'],
Broj_telefona: data['Broj_telefona'],
jmbg: data['jmbg'],
Nivo: data['Nivo']
}
});
console.log(this.user);
console.log(this.getUserData);
}
this is class User
export class User {
constructor(
Ime: any,
Prezime: any,
Username: any,
Sifra: any,
Broj_telefona: any,
jmbg: any,
Nivo: any
) {}
}
onSubmit()
{
this.http.post('some/api',
JSON.stringify({
user_name: this.login_form.value.user_name,
password: this.login_form.value.password
}),
this.options
)
.subscribe(data => {
this.getUserData = data[0];
this.user = {
Ime: data['Ime'],
Prezime: data['Prezime'],
Username: data['Username'],
Sifra: data['Sifra'],
Broj_telefona: data['Broj_telefona'],
jmbg: data['jmbg'],
Nivo: data['Nivo']
}
});
console.log(this.user);
console.log(this.getUserData);
}
this is class User
export class User {
constructor(
Ime: any,
Prezime: any,
Username: any,
Sifra: any,
Broj_telefona: any,
jmbg: any,
Nivo: any
) {}
}
onSubmit()
{
this.http.post('some/api',
JSON.stringify({
user_name: this.login_form.value.user_name,
password: this.login_form.value.password
}),
this.options
)
.subscribe(data => {
this.getUserData = data[0];
this.user = {
Ime: data['Ime'],
Prezime: data['Prezime'],
Username: data['Username'],
Sifra: data['Sifra'],
Broj_telefona: data['Broj_telefona'],
jmbg: data['jmbg'],
Nivo: data['Nivo']
}
});
console.log(this.user);
console.log(this.getUserData);
}
this is class User
export class User {
constructor(
Ime: any,
Prezime: any,
Username: any,
Sifra: any,
Broj_telefona: any,
jmbg: any,
Nivo: any
) {}
}
angular
angular
edited Nov 16 '18 at 3:22
georgeawg
33.8k105170
33.8k105170
asked Nov 15 '18 at 11:48
Demir AgovicDemir Agovic
63
63
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Use console.log
inside the subscribe block like this -
onSubmit()
{
this.http.post('some/api',
JSON.stringify({
user_name: this.login_form.value.user_name,
password: this.login_form.value.password
}),
this.options
)
.subscribe(data => {
this.getUserData = data[0];
this.user = {
Ime: data['Ime'],
Prezime: data['Prezime'],
Username: data['Username'],
Sifra: data['Sifra'],
Broj_telefona: data['Broj_telefona'],
jmbg: data['jmbg'],
Nivo: data['Nivo']
}
console.log(this.user);
console.log(this.getUserData);
});
}
As you are using http
method which is asynchronous but console.log
is running before this call.
Yes, this work but I must use this data and set to cookie or local storage.
– Demir Agovic
Nov 15 '18 at 11:51
Yes , so you need to set it to localstorage into subscribe block itself
– Pardeep Jain
Nov 15 '18 at 11:52
1
Thats is problem. I fix it. Thanks.
– Demir Agovic
Nov 15 '18 at 13:58
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%2f53318815%2fangular-how-to-use-data-from-subcribe-or-map-and-set-in-object-after-post-requ%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use console.log
inside the subscribe block like this -
onSubmit()
{
this.http.post('some/api',
JSON.stringify({
user_name: this.login_form.value.user_name,
password: this.login_form.value.password
}),
this.options
)
.subscribe(data => {
this.getUserData = data[0];
this.user = {
Ime: data['Ime'],
Prezime: data['Prezime'],
Username: data['Username'],
Sifra: data['Sifra'],
Broj_telefona: data['Broj_telefona'],
jmbg: data['jmbg'],
Nivo: data['Nivo']
}
console.log(this.user);
console.log(this.getUserData);
});
}
As you are using http
method which is asynchronous but console.log
is running before this call.
Yes, this work but I must use this data and set to cookie or local storage.
– Demir Agovic
Nov 15 '18 at 11:51
Yes , so you need to set it to localstorage into subscribe block itself
– Pardeep Jain
Nov 15 '18 at 11:52
1
Thats is problem. I fix it. Thanks.
– Demir Agovic
Nov 15 '18 at 13:58
add a comment |
Use console.log
inside the subscribe block like this -
onSubmit()
{
this.http.post('some/api',
JSON.stringify({
user_name: this.login_form.value.user_name,
password: this.login_form.value.password
}),
this.options
)
.subscribe(data => {
this.getUserData = data[0];
this.user = {
Ime: data['Ime'],
Prezime: data['Prezime'],
Username: data['Username'],
Sifra: data['Sifra'],
Broj_telefona: data['Broj_telefona'],
jmbg: data['jmbg'],
Nivo: data['Nivo']
}
console.log(this.user);
console.log(this.getUserData);
});
}
As you are using http
method which is asynchronous but console.log
is running before this call.
Yes, this work but I must use this data and set to cookie or local storage.
– Demir Agovic
Nov 15 '18 at 11:51
Yes , so you need to set it to localstorage into subscribe block itself
– Pardeep Jain
Nov 15 '18 at 11:52
1
Thats is problem. I fix it. Thanks.
– Demir Agovic
Nov 15 '18 at 13:58
add a comment |
Use console.log
inside the subscribe block like this -
onSubmit()
{
this.http.post('some/api',
JSON.stringify({
user_name: this.login_form.value.user_name,
password: this.login_form.value.password
}),
this.options
)
.subscribe(data => {
this.getUserData = data[0];
this.user = {
Ime: data['Ime'],
Prezime: data['Prezime'],
Username: data['Username'],
Sifra: data['Sifra'],
Broj_telefona: data['Broj_telefona'],
jmbg: data['jmbg'],
Nivo: data['Nivo']
}
console.log(this.user);
console.log(this.getUserData);
});
}
As you are using http
method which is asynchronous but console.log
is running before this call.
Use console.log
inside the subscribe block like this -
onSubmit()
{
this.http.post('some/api',
JSON.stringify({
user_name: this.login_form.value.user_name,
password: this.login_form.value.password
}),
this.options
)
.subscribe(data => {
this.getUserData = data[0];
this.user = {
Ime: data['Ime'],
Prezime: data['Prezime'],
Username: data['Username'],
Sifra: data['Sifra'],
Broj_telefona: data['Broj_telefona'],
jmbg: data['jmbg'],
Nivo: data['Nivo']
}
console.log(this.user);
console.log(this.getUserData);
});
}
As you are using http
method which is asynchronous but console.log
is running before this call.
edited Nov 15 '18 at 11:51
answered Nov 15 '18 at 11:50
Pardeep JainPardeep Jain
41.2k17103146
41.2k17103146
Yes, this work but I must use this data and set to cookie or local storage.
– Demir Agovic
Nov 15 '18 at 11:51
Yes , so you need to set it to localstorage into subscribe block itself
– Pardeep Jain
Nov 15 '18 at 11:52
1
Thats is problem. I fix it. Thanks.
– Demir Agovic
Nov 15 '18 at 13:58
add a comment |
Yes, this work but I must use this data and set to cookie or local storage.
– Demir Agovic
Nov 15 '18 at 11:51
Yes , so you need to set it to localstorage into subscribe block itself
– Pardeep Jain
Nov 15 '18 at 11:52
1
Thats is problem. I fix it. Thanks.
– Demir Agovic
Nov 15 '18 at 13:58
Yes, this work but I must use this data and set to cookie or local storage.
– Demir Agovic
Nov 15 '18 at 11:51
Yes, this work but I must use this data and set to cookie or local storage.
– Demir Agovic
Nov 15 '18 at 11:51
Yes , so you need to set it to localstorage into subscribe block itself
– Pardeep Jain
Nov 15 '18 at 11:52
Yes , so you need to set it to localstorage into subscribe block itself
– Pardeep Jain
Nov 15 '18 at 11:52
1
1
Thats is problem. I fix it. Thanks.
– Demir Agovic
Nov 15 '18 at 13:58
Thats is problem. I fix it. Thanks.
– Demir Agovic
Nov 15 '18 at 13:58
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.
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%2f53318815%2fangular-how-to-use-data-from-subcribe-or-map-and-set-in-object-after-post-requ%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