这是我的代码,无法进行Ajax调用,在此处获取错误。不知道如何清除,有人可以帮助我。
var app = angular.module('app',['ui.router']);
app.controller('PostCtrl',['$scope','$http',function($scope,$http){
console.log('inside jobpost');
$http.get("/api/job-posts").success(function(data, status, headers, config) {
$scope.items = data.data;
}).error(function(data, status, headers, config) {
console.log("No data found..");
});
});
app.filter('searchFor', function(){
return function(arr, searchString){
if(!searchString){
return arr;
}
var result = [];
searchString = searchString.toLowerCase();
angular.forEach(arr, function(item){
if(item.title.toLowerCase().indexOf(searchString) !== -1){
result.push(item);
}
});
return result;
};
}]);
<!-- <body ng-app="app"> -->
<div ng-controller="PostCtrl">
<h3 class="headName">Ajax search using AngularJs</h3>
<div class="bar">
<input type="text" class="search" ng-model="searchString" placeholder="Enter your search terms" />
</div>
<ul class="data-ctrl">
<li ng-repeat="i in items | searchFor:searchString">
<p>{{i.title}}
</li>
</ul>
我尝试在很多方面解决这个问题,但无法清除。
答案 0 :(得分:0)
试试这个......
你在第33行遗失了)
var app = angular.module('app',['ui.router']);
app.controller('PostCtrl',['$scope','$http',function($scope,$http){
console.log('inside jobpost');
$http.get("/api/job-posts").success(function(data, status, headers, config) {
$scope.items = data.data;
}).error(function(data, status, headers, config) {
console.log("No data found..");
});
}]);
app.filter('searchFor', function(){
return function(arr, searchString){
if(!searchString){
return arr;
}
var result = [];
searchString = searchString.toLowerCase();
angular.forEach(arr, function(item){
if(item.title.toLowerCase().indexOf(searchString) !== -1){
result.push(item);
}
});
return result;
};
});