简体   繁体   中英

AngularJS array filter not working

How can I make the this filter work?

<div ng-repeat="rvs in reviews | filter:{ Name:'{{ r.Name }}' }">
 {{ rvs.Name }}
</div>

'r.Name' comes from other array "r in restaurants"

However, instead of r.Name directly putting the string works, like this:

<div ng-repeat="rvs in reviews | filter:{ Name:'John' }">
 {{ rvs.Name }}
</div>

Array Files

'reviews'

{
  "reviews": [
    {
      "Name": "Sagar Ratna",
      "Reviewer": "Jaskaran",
      "Comments": "Great service, healthy food!",
      "Date": "25th Sept. 2016",
      "Rating" : "4"
    },
    {
      "Name": "The Night Factory",
      "Reviewer": "Pawandeep",
      "Comments": "Nice location, ok service!",
      "Date": "29th Sept. 2016",
      "Rating" : "3"
    }
  ]
}

Restaurants

{
  "records": [
    {
      "Name": "Sagar Ratna",
      "Image": "./images/sr.jpg",
      "Address": "Mohali",
      "Type": "South Indian",
      "Hours" : "10:00-23:30"
    },
    {
      "Name": "The Night Factory",
      "Image": "./images/nf.jpg",
      "Address": "Chandigarh",
      "Type": "South Indian",
      "Hours" : "24/7"
    }
  ]
}

Remove '{{}}' from '{{r.Name}}'

<div ng-repeat="rvs in reviews | filter:{ Name:  r.Name  }">
 {{ rvs.Name }}
</div>

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