0

This console log is working properly. How to get this data for the html.

ProductController.js

$scope.selectedProduct = function(product)
 {
    console.log(product.post_title);
    console.log(product.ID);
    console.log(product.post_date);
    console.log(product.post_author);
 }

ProductDetails.html

<ion-item class="item widget uib_w_109 d-margins item-button-left" data-uib="ionic/list_item_button" data-ver="0">
        Product Name : {{product.post_title}} <br>
            Product Id : {{product.ID}}<br>
</ion-item>

5
  • Would you like to fetch data from server then show that in HTML? Commented Jul 29, 2016 at 5:33
  • yes this data from server. Commented Jul 29, 2016 at 5:36
  • <ion-item class="item widget uib_w_109 d-margins item-button-left" data-uib="ionic/list_item_button" data-ver="0"> Product Name : {{selectedProduct.post_title}} <br> Product Id : {{selectedProduct.ID}}<br> </ion-item> use this Commented Jul 29, 2016 at 5:43
  • this answer also not working my friend. pls can you help me Commented Jul 29, 2016 at 6:21
  • Cab you show just result of console.log(product)! Commented Jul 29, 2016 at 7:59

8 Answers 8

2

You need to assign to $scope variable,

$scope.selectedProduct = function(product)
 {
    $scope.product.post_title = product.post_title;
    $scope.product.ID = product.ID;
    ........
 }

if you want to push it to an array,

$scope.products =[];
$scope.products.push($scope.product);
Sign up to request clarification or add additional context in comments.

5 Comments

'undefined' is not an object (evaluating '$scope.product.post_title = product.post_title') Now, I have this error
you need to declare the $scope.poduct variable initially, something like this $scope.product = {};
how to set this data into array
$scope.products.push($scope.product);
give me team viewer
2

Assign those values into a scope variable and try calling those scope variables in HTML.enter image description here

5 Comments

$scope.selectedProduct = function(product) { $scope.productPostTitle = product.post_title; $scope.productID = product.ID; }
is there any fiddle available for your problem?
'undefined' is not an object (evaluating '$scope.product.post_title = product.post_title') Now I have this error
hope the image will help you!
can u post a snapshot of your code completely including html? else u could have create a fiddle
1

Just set the product passed as parameter to a scope variable, then bind or use the scope variable in HTML.

here is a working plunker : https://plnkr.co/edit/caqLK8oOIukeNuPQed3h?p=preview

  $scope.product = {};
  $scope.selectedProduct = function(product) {
    $scope.product.post_title = product.post_title;
    $scope.product.ID = product.ID;
    $scope.product.post_date = product.post_date;
    $scopee.product.post_author = product.post_author;

  };

in Plunker button gets the product from server and calls a function to set the product. as plunker doesnt have server request the product to be fetched is defined statically.

11 Comments

This is not working my friend. This Plunker also not working
sorry had version issues, please try again, i have updated the plunker, Run it and button click will fetch the values.
It will working on Plunker now. What I need to use for this my friend. productFetched
@DRK the 'productFetched' variable is statically defined, you need to get the data from the server , which will update the product right?
How I can get data my friend. pls can you help me
|
0

Change your javascript and html code as below:

JS

$scope.selectedProduct = function(product){
    return product;
}

HTML

<ion-item class="item widget uib_w_109 d-margins item-button-left" data-uib="ionic/list_item_button" data-ver="0">
    Product Name : {{selectedProduct.post_title}} <br>
    Product Id : {{selectedProduct.ID}}<br>
</ion-item>

Regards.

2 Comments

Please provide some info about error. or may be create fiddle to show that what you are trying out.
can you answer this question my friend.. stackoverflow.com/questions/38431873/…
0

You will have to store the values in $scope variable and also need to mention ng-controller attribute in the parent element. Here is a full code with example

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
<div ng-app="app1">
	<div ng-controller="ctrl1">
		Employee Info<br/>
		<strong>Id:</strong> {{employeeId}}<br/>
		<strong>Name:</strong> {{employeeName}}
	</div>
</div>

<script>
var app = angular.module('app1', []);
app.controller('ctrl1', function($scope) {
    $scope.employeeId= "E001";
    $scope.employeeName= "John Doe";
});
</script>

Comments

0

Start by declaring a ´$scope´ variable :

$scope.product = {};

Then assign it a value in your fonction :

$scope.selectedProduct = function(product) {
    $scope.product.ID = product.ID;
   ... 
}

EDIT

This fiddle is working, is there any difference in your code?

9 Comments

'undefined' is not an object (evaluating '$scope.product.post_title = product.post_title') Now I have this error my friend
It seems like your ´$scope´ isn't declared, what do you get when you do : ´console.log($scope)´ ?
i'm checking with safari browser my friend. pls can you help me,
Just write ´console.log($scope)´ in your function and paste the output here please.
selectedProduct: function (product) { arguments: null caller: null length: 1 name: "" Showing like this
|
0

If you've a single value then you can access that by using [0] upset else you can do it by using ng-repeat.

Please check following code.

angular.module('appTest', [])
  .controller("repeatCtrl", function($scope) {
    $scope.items = [{
      Name: "Soap",
      Price: "25",
      Quantity: "10"
    }, {
      Name: "Bag",
      Price: "100",
      Quantity: "15"
    }, {
      Name: "Pen",
      Price: "15",
      Quantity: "13"
    }];
  
  $scope.result = {};
  $scope.selectProduct = function(product){
    $scope.result = product;
  };
  })
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="appTest">
  <section ng-controller="repeatCtrl">
    <table>
      <thead>
        <tr ng-repeat="item in items | limitTo:1">
          <th ng-repeat="(key, val) in item">
            {{key}}
          </th>
        </tr>
      </thead>
      <tbody>
        <tr ng-repeat="item in items">
          <td ng-repeat="(key, val) in item">
            <a href="#" ng-click="selectProduct(item)">{{val}}</a>
          </td>
        </tr>
      </tbody>
    </table>
    <br/>
    <div>
    Name : {{result.Name}} <br/>
    Price : {{result.Price}} <br/>
    Quantity : {{result.Quantity}}  
      
    </div>
  </section>
  
</body>

8 Comments

What's the problem ?
Do you've single value or multiple values in loop ?
In this link i have array. stackoverflow.com/questions/38366856/…
I've updated my code, please check now. You can just replace the "title" with product.title and so on.
|
0

Just do this...

$scope.product{

}

$scope.selectedProduct = function(product)
{
    $scope.product.post_title = product.post_title;
    $scope.product.ID = product.ID;
    $scope.product.post_date = product.post_date;
     $scopee.product.post_author =product.post_author;
}

or you can simply do...

$scope.product{

}

$scope.selectedProduct = function(product)
 {
    $scope.product = product;
 }

1 Comment

'undefined' is not an object (evaluating '$scope.product.post_title = product.post_title') Then I have this error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.