how do i assign data received from post request to an observable? - IONIC3










0















Hey guys so i am building an IONIC 3 application which is to access an API and make POST and GET requests. I have a problem in subscribing the data received from the POST request to an Observable variable. My objective of the code is to send a post request and display a list of products from the data returned. The following is my code, however i am unable to subscribe the data to the observable as i do with the get request:



public products_detail: Observable<any>;

this.httpClient.post("http://www.xxx.asia/app_test/detail_shop_meals.json", postData)
this.products_detail.subscribe(data =>
json_load = data.toString();
this.meal_available = data;
shop_name = document.getElementById("shop_name").innerHTML = data.shop_name;
food_type = document.getElementById("food_type").innerHTML = data.shop_description;
fee = document.getElementById("fee").innerHTML = "฿"+ data.price
console.log('my data: ', data);
console.log('look here:', data.detail_meals_popular[0].name)
//return this.products_detail = json_load;
, error =>
console.log(error);
);


and the html to display the products is as follows:



<h4>Most Popular</h4>
<ul>
<li ion-item *ngFor="let x of (products_detail | async)?.detail_meals_popular" (click)="item()">
<div class="list_circle">
<img src="assets/imgs/item2.png" alt="food">
</div>
<div class="list_circle_detail">
<h5> x.name </h5>
<p> x.description </p>
<strong>฿ x.price </strong>
</div>
<div class="clear"></div>
</li>
</ul>


id like to use the observable variable to list the products in my html, thank you in advance for the help guys :-)










share|improve this question
























  • where is products_detail set? is it the http post call?

    – Suraj Rao
    Nov 13 '18 at 7:15











  • @SurajRao products_detail is an observable variable and its set just under the export class

    – CodeMONSTER
    Nov 13 '18 at 7:21











  • No, it's not initialized there. It's only declared. You need to subscribe on the Observable that is returned by the call to this.httpClient.post(...). And don't use document.getElementById(): change the state of your component, and use the template to display that state.

    – JB Nizet
    Nov 13 '18 at 7:24















0















Hey guys so i am building an IONIC 3 application which is to access an API and make POST and GET requests. I have a problem in subscribing the data received from the POST request to an Observable variable. My objective of the code is to send a post request and display a list of products from the data returned. The following is my code, however i am unable to subscribe the data to the observable as i do with the get request:



public products_detail: Observable<any>;

this.httpClient.post("http://www.xxx.asia/app_test/detail_shop_meals.json", postData)
this.products_detail.subscribe(data =>
json_load = data.toString();
this.meal_available = data;
shop_name = document.getElementById("shop_name").innerHTML = data.shop_name;
food_type = document.getElementById("food_type").innerHTML = data.shop_description;
fee = document.getElementById("fee").innerHTML = "฿"+ data.price
console.log('my data: ', data);
console.log('look here:', data.detail_meals_popular[0].name)
//return this.products_detail = json_load;
, error =>
console.log(error);
);


and the html to display the products is as follows:



<h4>Most Popular</h4>
<ul>
<li ion-item *ngFor="let x of (products_detail | async)?.detail_meals_popular" (click)="item()">
<div class="list_circle">
<img src="assets/imgs/item2.png" alt="food">
</div>
<div class="list_circle_detail">
<h5> x.name </h5>
<p> x.description </p>
<strong>฿ x.price </strong>
</div>
<div class="clear"></div>
</li>
</ul>


id like to use the observable variable to list the products in my html, thank you in advance for the help guys :-)










share|improve this question
























  • where is products_detail set? is it the http post call?

    – Suraj Rao
    Nov 13 '18 at 7:15











  • @SurajRao products_detail is an observable variable and its set just under the export class

    – CodeMONSTER
    Nov 13 '18 at 7:21











  • No, it's not initialized there. It's only declared. You need to subscribe on the Observable that is returned by the call to this.httpClient.post(...). And don't use document.getElementById(): change the state of your component, and use the template to display that state.

    – JB Nizet
    Nov 13 '18 at 7:24













0












0








0








Hey guys so i am building an IONIC 3 application which is to access an API and make POST and GET requests. I have a problem in subscribing the data received from the POST request to an Observable variable. My objective of the code is to send a post request and display a list of products from the data returned. The following is my code, however i am unable to subscribe the data to the observable as i do with the get request:



public products_detail: Observable<any>;

this.httpClient.post("http://www.xxx.asia/app_test/detail_shop_meals.json", postData)
this.products_detail.subscribe(data =>
json_load = data.toString();
this.meal_available = data;
shop_name = document.getElementById("shop_name").innerHTML = data.shop_name;
food_type = document.getElementById("food_type").innerHTML = data.shop_description;
fee = document.getElementById("fee").innerHTML = "฿"+ data.price
console.log('my data: ', data);
console.log('look here:', data.detail_meals_popular[0].name)
//return this.products_detail = json_load;
, error =>
console.log(error);
);


and the html to display the products is as follows:



<h4>Most Popular</h4>
<ul>
<li ion-item *ngFor="let x of (products_detail | async)?.detail_meals_popular" (click)="item()">
<div class="list_circle">
<img src="assets/imgs/item2.png" alt="food">
</div>
<div class="list_circle_detail">
<h5> x.name </h5>
<p> x.description </p>
<strong>฿ x.price </strong>
</div>
<div class="clear"></div>
</li>
</ul>


id like to use the observable variable to list the products in my html, thank you in advance for the help guys :-)










share|improve this question
















Hey guys so i am building an IONIC 3 application which is to access an API and make POST and GET requests. I have a problem in subscribing the data received from the POST request to an Observable variable. My objective of the code is to send a post request and display a list of products from the data returned. The following is my code, however i am unable to subscribe the data to the observable as i do with the get request:



public products_detail: Observable<any>;

this.httpClient.post("http://www.xxx.asia/app_test/detail_shop_meals.json", postData)
this.products_detail.subscribe(data =>
json_load = data.toString();
this.meal_available = data;
shop_name = document.getElementById("shop_name").innerHTML = data.shop_name;
food_type = document.getElementById("food_type").innerHTML = data.shop_description;
fee = document.getElementById("fee").innerHTML = "฿"+ data.price
console.log('my data: ', data);
console.log('look here:', data.detail_meals_popular[0].name)
//return this.products_detail = json_load;
, error =>
console.log(error);
);


and the html to display the products is as follows:



<h4>Most Popular</h4>
<ul>
<li ion-item *ngFor="let x of (products_detail | async)?.detail_meals_popular" (click)="item()">
<div class="list_circle">
<img src="assets/imgs/item2.png" alt="food">
</div>
<div class="list_circle_detail">
<h5> x.name </h5>
<p> x.description </p>
<strong>฿ x.price </strong>
</div>
<div class="clear"></div>
</li>
</ul>


id like to use the observable variable to list the products in my html, thank you in advance for the help guys :-)







angular rest ionic3 observable apprequests






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 7:17









georgeawg

33.1k104968




33.1k104968










asked Nov 13 '18 at 5:57









CodeMONSTERCodeMONSTER

12




12












  • where is products_detail set? is it the http post call?

    – Suraj Rao
    Nov 13 '18 at 7:15











  • @SurajRao products_detail is an observable variable and its set just under the export class

    – CodeMONSTER
    Nov 13 '18 at 7:21











  • No, it's not initialized there. It's only declared. You need to subscribe on the Observable that is returned by the call to this.httpClient.post(...). And don't use document.getElementById(): change the state of your component, and use the template to display that state.

    – JB Nizet
    Nov 13 '18 at 7:24

















  • where is products_detail set? is it the http post call?

    – Suraj Rao
    Nov 13 '18 at 7:15











  • @SurajRao products_detail is an observable variable and its set just under the export class

    – CodeMONSTER
    Nov 13 '18 at 7:21











  • No, it's not initialized there. It's only declared. You need to subscribe on the Observable that is returned by the call to this.httpClient.post(...). And don't use document.getElementById(): change the state of your component, and use the template to display that state.

    – JB Nizet
    Nov 13 '18 at 7:24
















where is products_detail set? is it the http post call?

– Suraj Rao
Nov 13 '18 at 7:15





where is products_detail set? is it the http post call?

– Suraj Rao
Nov 13 '18 at 7:15













@SurajRao products_detail is an observable variable and its set just under the export class

– CodeMONSTER
Nov 13 '18 at 7:21





@SurajRao products_detail is an observable variable and its set just under the export class

– CodeMONSTER
Nov 13 '18 at 7:21













No, it's not initialized there. It's only declared. You need to subscribe on the Observable that is returned by the call to this.httpClient.post(...). And don't use document.getElementById(): change the state of your component, and use the template to display that state.

– JB Nizet
Nov 13 '18 at 7:24





No, it's not initialized there. It's only declared. You need to subscribe on the Observable that is returned by the call to this.httpClient.post(...). And don't use document.getElementById(): change the state of your component, and use the template to display that state.

– JB Nizet
Nov 13 '18 at 7:24












0






active

oldest

votes











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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274679%2fhow-do-i-assign-data-received-from-post-request-to-an-observable-ionic3%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274679%2fhow-do-i-assign-data-received-from-post-request-to-an-observable-ionic3%23new-answer', 'question_page');

);

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







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo