简体   繁体   中英

How can I filter children properties by parent property in Angular JS?

How can I filter the below JSON object so that I only display names that have a date of '01-2015'? When I try using the filter method below I end up getting what looks like "[] []" in the HTML content. If there is a solution, how can I display each array item of names instead of having the HTML return ['Susan Hill', 'Petrona Morgan']?

var annApp = angular.module('anniversaries', []);

<div ng-app="anniversaries" class="row" ng-controller="annList">
<div class="mdl-card__supporting-text text2" >
    <p ng-repeat="ann in anns">{{ ann.names | filter:{$:"01-2015"} }}</p>
</div>
<script>
annApp.controller('annList', function ($scope) {
  $scope.anns = [
    {'date':'01-2015','year': '45', 
    'names': ['Susan Hill', 'Petrona Morgan ']},
    {'date': '01-2015', 'year': '35',
    'names': ['Terisa Branson', 'Jo Fox', 'Genette McKown']}
  ];
}); 
</script>

Try

<p ng-repeat="ann in anns | filter: {date : '01-2015'}">
  <span ng-repeat="name in ann.names">{{name}}<br/></span>
</p>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM