myFilter라는 자체 필터를 만들고 myFilter를 통해 사람 배열을 파이프하려고합니다. 결과물은 "이름 입력 :"이고 텍스트 상자가옵니다. A 또는 B 또는 C와 같은 글자를 쓰려고해도 아무 것도 표시되지 않습니다.사용자가 텍스트 상자에 입력 한 내용에 따라 목록을 필터링하고 싶습니다. angularJS를 사용하고 있습니다. 코드가 작동하지 않는 이유는 무엇입니까?
<!DOCTYPE html>
<html>
<head>
<script src
="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js">
</script>
</head>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<p>Enter name: <input type="text" ng-model="test" /></p>
<ul>
<li ng-repeat="x in person | myFilter">
{{x}}
</li>
</ul>
</div>
<script>
var app = angular.module('myApp', []);
app.filter('myFilter', function()
{
return function(x, test)
{
var i, c=0;
for (i=0; i<test.length; i++)
{
if (x[i] == test[i])
{
c++;
}
}
if (c==test.length)
{
return x;
}
}
});
app.controller('myCtrl', function($scope)
{
$scope.person = ['Alex', 'Buddy',
'Bob', 'Aaron', 'Clay', 'Clayton'];
});
</script>
</body>
</html>
이 완벽하게 작동 않지만 test'이 – user184994