angularjs - Display nested data from all object using ng-repeat -
hey have database many products , in every products has comments , display every comments using ng-repeat. data.data.products
there object in database , comments
comment every object. e.g. have 5 object in database , 6 comments every in. , question how dispaly comments objects? try use this:
user.getproducts().then(function(data){ for(i=0; < data.data.products.length; i++) app.usercomments = data.data.products[i].comments; })
html
<div ng-repeat="comment in main.usercomments" class="item"> <blockquote> <p>{{comment.body}}</p> </blockquote> </div>
schema
var productschema = new schema({ comments: [{ body: { type: string, trim: true, }, author: { type: string, }, date: { type: date, } }] });
just assign returned data web service controller variable, , then, using 'controller as' syntax, iterate through them in view ng-repeat
.
<html ng-app="sampleapp"> <head> <meta charset="utf-8" /> <title>sample app</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js"></script> <script> var myapp = angular.module('sampleapp', []); myapp.controller('samplecontroller', function() { this.data = [ { product: 'a great product', comments: 'a sample comment' }, { product: 'another great product', comments: 'another sample comment' } ]; }); </script> </head> <body ng-controller="samplecontroller samplectrl"> <div ng-repeat="item in samplectrl.data"> <blockquote> <p>{{item.comments}}</p> </blockquote> </div> </body> </html>
Comments
Post a Comment