我有以下记录我希望按名称过滤ng-repeat我输入但是它不起作用请帮我这个
ng-repeat="contact in vm.contacts | filter: {name: vm.chatSearch}
"userlist": [
{
"_id": "59edd7c5ff809c1c4c7a43c2",
"updatedDatetime": "2017-10-23T11:51:33.106Z",
"createdDatetime": "2017-10-23T11:51:33.106Z",
"user_id": {
"_id": "59f07d5c935f27764c8d1090",
"name": "james"
},
"__v": 0
}
]
答案 0 :(得分:0)
尝试:
ng-repeat="contact in vm.contacts | filter: {user_id: {name: vm.chatSearch}}"
示例:的
<ul>
<li ng-repeat="contact in contacts | filter: {user_id: {name: chatSearch}}">
{{contact.name}} user_id: {{contact.user_id.name}}
</li>
</ul>
答案 1 :(得分:0)
我的以下示例可能会帮助您
<强> HTML 强>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body ng-controller="MyCtrl">
<input ng-model="results.year">
<div ng-repeat="subject in results.subjects | filter:{grade:'A'}">
<input ng-model="subject.title" />
</div>
</body>
</html>
&#13;
<强> JS 强>
function MyCtrl($scope) {
$scope.results = {
year:2013,
subjects:[
{title:'English',grade:'A'},
{title:'Maths',grade:'A'},
{title:'Science',grade:'B'},
{title:'Geography',grade:'C'}
]
};
}
谢谢, 阿伦
答案 2 :(得分:0)
你需要这样的东西,
<li ng-repeat="user in vm.contacts | filter: {user_id: {name: searchterm}}"><span>{{user.user_id.name}}</span></li>
<强>样本强>
var app = angular.module('myapp',[]);
app.controller('personController',function(){
var vm = this;
vm.contacts = [
{
"_id": "59edd7c5ff809c1c4c7a43c2",
"updatedDatetime": "2017-10-23T11:51:33.106Z",
"createdDatetime": "2017-10-23T11:51:33.106Z",
"user_id": {
"_id": "59f07d5c935f27764c8d1090",
"name": "james"
},
"__v": 0
}
];
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app = "myapp" ng-controller = "personController as vm">
<input ng-model="searchterm"/>
<ul>
<li ng-repeat="user in vm.contacts | filter: {user_id: {name: searchterm}}"><span>{{user.user_id.name}}</span></li>
</ul>
</div>
&#13;