【发布时间】:2016-11-08 22:11:50
【问题描述】:
我正在使用 Ionic 框架创建一个混合应用程序,并设置了一个工厂来保存一组对象。我想使用 $filter 服务来抓取数组中具有特定 ID 的对象。这是我现在拥有的代码。我从这个堆栈溢出问题中得到了这个实现的想法:In Angular, I need to search objects in an array。
angular.module('prototype.services', [])
.factory('Patients', function($filter) {
var currentID;
var currentPatient = $filter('patientFilter')(patients, {id: currentID}, true);
var patients = [{
id: 1,
name: 'Alexander Hamilton'
}];
return {
all:function() {
return patients;
},
add: function(patient) {
patients.push( {
name: patient.name
})
},
setID: function(id) {
currentID = id;
},
getID: function() {
return currentID;
},
};
});
据我了解,这应该可以工作,因为我将 $filter 注入了我创建的工厂。我对 Angular 很陌生,所以我可能缺少一些明显的东西。
完全错误是:
ionic.bundle.js:26794 Error: [$injector:unpr] Unknown provider: patientFilterFilterProvider <- patientFilterFilter <- Patients
http://errors.angularjs.org/1.5.3/$injector/unpr? p0=patientFilterFilterProvider%20%3C-%20patientFilterFilter%20%3C-%20Patients
at ionic.bundle.js:13438
at ionic.bundle.js:17788
at Object.getService [as get] (ionic.bundle.js:17941)
at ionic.bundle.js:17793
at Object.getService [as get] (ionic.bundle.js:17941)
at ionic.bundle.js:32697
at Object.<anonymous> (services.js:6)
at Object.invoke (ionic.bundle.js:17995)
at Object.enforcedReturnValue [as $get] (ionic.bundle.js:17834)
at Object.invoke (ionic.bundle.js:17995)
【问题讨论】:
-
你在缩小你的代码吗?
-
@SteamDev 我不相信我是,而且我对角度或离子没有太多经验来看看我是否是。但是,我确实将工厂语句更改为 .factory('Patients' , ['$filter', function($filter) { 以防万一,但我仍然收到错误。
-
能否包含定义患者过滤器的代码?
标签: angularjs filter ionic-framework runtime-error