3

I have category array. there are more products. I need show categories in category page. when click on a category, I have to redirect the product page and show the necessary products. When click on a product, I have to redirect the product_details page and show the necessary product details.

category loaded to the category page, when click on that it will redirect the product page. But, I cant see products. And what are the errors of these controllers, and how to create "product_details.html", and "product.html" page also.

I have to show like this :

  • category page : term_id, name
  • product page : post_title, ID
  • product details page : post_title, post_date, post_author, ID

categorylist-product.json

{
"category": [{
    "term_id": "10",
    "name": "Arden Grange",
    "slug": "arden-grange",
    "products": [{
        "ID": "47",
        "post_title": "Arden Grange, Premium",
        "post_date": "2015-10-20 16:13:04",
        "post_author": "5"
    }, {
        "ID": "50",
        "post_title": "Arden Grange Puppy\/Junior Large Breed",
        "post_date": "2015-10-21 04:56:23",
        "post_author": "5"
    }, {
        "ID": "53",
        "post_title": "Arden Grange Weaning\/Puppy",
        "post_date": "2015-10-22 12:52:35",
        "post_author": "5"
    }]
}, {
    "term_id": "8",
    "name": "Menu 1",
    "slug": "menu-1",
    "products": [{
        "ID": "38",
        "post_title": "Home",
        "post_date": "2015-10-20 10:43:44",
        "post_author": "1"
    }, {
        "ID": "30",
        "post_title": "",
        "post_date": "2015-10-20 10:13:56",
        "post_author": "1"
    }, {
        "ID": "31",
        "post_title": "",
        "post_date": "2015-10-20 10:13:57",
        "post_author": "1"
    }]
}]
}

CategoryController.js

app.controller('CategoryController', ['$scope','category', function($scope, category) {

 category.success(function(data) {
     $scope.userslists = data;
});

}]);

ProductController.js

app.controller('ProductController', ['$scope', '$routeParams', 'category', function($scope, $routeParams, category,products) {

category.success(function(data) {
$scope.users = data.category[$routeParams.id];

});
}]);

app.js

var app = angular.module('LookApp', ['ionic','ngCordova','ngRoute']);

app.config(function($stateProvider, $urlRouterProvider,$routeProvider) {
$routeProvider

.when('/', {
controller: 'CategoryController',
templateUrl: 'views/category.html'
})

.when('/:id', {
controller: 'ProductController',
templateUrl: 'views/users.html'
})
 .when('/login/:friendId', {
controller: 'LoginController',
templateUrl: 'views/login.html'
})

.otherwise({
redirectTo: '/'

});

category.js (Service file)

app.factory('category', ['$http', function($http) {    

return $http.get('http://localhost/youtubewebservice/shop-categorylist-product.php')


       .success(function(data) { 
          return data; 
        }) 
        .error(function(err) { 
          return err; 
        }); 
}]);
4
  • you need to put userslists in category,product and details pages Commented May 9, 2016 at 5:26
  • I have to put data like this : " category page : term_id, name" . " product page : post_title, ID ". " product details page : post_title, post_date, post_author, ID " Commented May 9, 2016 at 5:31
  • do you want to show all data or only that particular term_id's details in other pages ?? Commented May 9, 2016 at 5:39
  • only the particular term_id's details my friend. Commented May 9, 2016 at 5:49

1 Answer 1

0

see you have put your data in $scope.userlists so when you call your data in html then you need to do like this
category page

<div ng-repeat="user in userslists">
Term ID : {{user.category.term_id}}
Name    : {{user.category.name}}
</div>

product page

<div ng-repeat="user in userslists">
Post Title : {{user.category.products.post_title}}
ID         : {{user.category.products.ID}}
</div>

Details page

<div ng-repeat="user in userslists">
Post Title : {{user.category.products.post_title}}
Post Date  : {{user.category.products.post_date}}
Post Author: {{user.category.products.post_author}}
ID         : {{user.category.products.ID}}
</div>
Sign up to request clarification or add additional context in comments.

4 Comments

not worked this code my friend. how to change the controllers.
Are you getting any data in controllers.js in $scope.userslists? And the json data you are getting is it in localhost/youtubewebservice/shop-categorylist-product.php
stackoverflow.com/questions/37103142/…... Can you answer this question. this is my full question my friend.
I getting this data from mysql DB using category.js (Service file). Categories will load to the category page. when click on the category, it will go to the product page also, but can't load the products.

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.