angularjs - Accessing value in sub nested object in JSON with Angular -


i'm trying access values in sub array objects of results:

results: [ {     list_name: "e-book fiction",     display_name: "e-book fiction",     bestsellers_date: "2016-09-03",     published_date: "2016-09-18",     rank: 1,     rank_last_week: 0,     weeks_on_list: 1,     asterisk: 0,     dagger: 0,     amazon_product_url: "http://rads.stackoverflow.com/amzn/click/1250022134", isbns: [],     book_details: [     {         title: "a great reckoning",         description: "an instructor @ police academy found murdered, perhaps 1 of cadets favored armand gamache, retired homicide chief of sûreté du québec.",         contributor: "by louise penny",         author: "louise penny",         contributor_note: "",         price: 0,         age_group: "",         publisher: "minotaur",         primary_isbn13: "9781250022127",         primary_isbn10: "1250022126"     }     ],     reviews: [     {         book_review_link: "",         first_chapter_link: "",         sunday_review_link: "",         article_chapter_link: ""     } ] } 

so can grab values title book_details, able display whole response with:

<article class="search-result row" ng-repeat="books in results">         <div class="col-xs-12 col-sm-12 col-md-3">             {{books}}         </div> </article> 

my controller simple, grabbing result:

mybooks.controller('bookcontroller', function($scope, $http){   $http.get("data-url")     .success(function(response) {       console.log(response);       $scope.results = response;     }); }); 

a screenshot of object in web console:

enter image description here

you can write . create new books array in scope iterating on results array.

app.controller("mycontroller", ["$scope","$http", function($scope, $http) {          $scope.books;           $http.get('test.json').then(function (response){               console.log(response.data.results);              $scope.results = response.data.results;              $scope.results.map(function(obj, index) {                if(obj.book_details) {                  if(!($scope.books)) {                    $scope.books = [];                  }                  for(var in obj.book_details) {                   $scope.books.push(obj.book_details[i]);                  }                }              });               console.log($scope.books);     });                  }]);  <article class="search-result row" ng-repeat="book in ">     <div class="col-xs-12 col-sm-12 col-md-3">         {{book.title}}     </div> </article> 

working link


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -