【发布时间】:2019-02-16 00:44:43
【问题描述】:
如何在代码中包含自定义过滤器?
这是我的服务文件。我需要按名称过滤。我还需要在 html 中进行验证以使用原始保存和取消
app.factory('CrusdService', function($http) {
return {
fetchAll: function() {
return $http.get('https:\\localHost:5000\countries').then(
function(response) {
return response.data.data; // depends on the response data.Sometimes it will be response.data.data.data
},
function(error) {
return error;
}
);
},
add: function(data) {
return $http.post('https:\\localHost:5000\country', data).then(
function(response) {
return response;
},
function(error) {
console.log('error');
}
);
},
update: function(data) {
var name = {
"name": data.name
};
return $http.put('https:\\localHost:5000\country' + data._id, name).then(
function(response) {
return response;
},
function(error) {
console.log('error');
}
);
},
activate: function(id) {
return $http.put('https:\\localHost:5000\country' + id + '\activate').then(
function(response) {
return response;
},
function(error) {
console.log('error');
}
);
},
deactivate: function(id) {
return $http.put('https:\\localHost:5000\country' + id + '\deactivate').then(
function(response) {
return response;
},
function(error) {
console.log('error');
}
);
}
}
});
【问题讨论】:
-
function countryList(){CrudeService.fecthAll().then(function(data){$scope.countries=data;},function(data){console.log('error');} );} countryList();CrudeService.add($scope.country).then(function(data){countryList();},function(data){console.log('error');});CrudeService.update ($scope.country).then(function(data){countryList();},function(data){console.log('error');});CrudeService.activate(itemsId).then(function(data) {countryList();},function(data){console.log('error');});CrudeService.deactivate(itemsId).then(function(data){countryList();},function(data){console .log('error');});
-
不要在 cmets 中添加代码,edit 你的问题。