【发布时间】:2016-10-10 12:05:57
【问题描述】:
我有一个可能很简单的问题。我之前在 Angular 中使用过服务,但现在在使用 MEANJS Yeoman Generator 项目时遇到了问题。我需要做的是在另一个模块中使用来自特定模块的数组数据,这样我就可以在另一个模型的视图中重复这个。
我在服务中究竟在哪里引入数组?
(function () {
'use strict';
angular
.module('patients')
.factory('PatientsService', PatientsService);
PatientsService.$inject = ['$resource'];
function PatientsService($resource) {
return $resource('api/patients/:patientId', {
patientId: '@_id'
}, {
update: {
method: 'PUT'
}
});
}
})();
到目前为止,我在 MEANJS Doc 中一无所获,这里也没有(仅来自具有另一种服务结构的较旧 MEANJS 版本)。
这是我想在服务中带来的内容:
// Shows a List of useable avatars on Patient creation
$scope.avatars = [
{ value:'1', name: 'modules/patients/client/img/avatar/avatar1.png' },
{ value:'2', name: 'modules/patients/client/img/avatar/avatar2.png' },
{ value:'3', name: 'modules/patients/client/img/avatar/avatar3.png' },
{ value:'4', name: 'modules/patients/client/img/avatar/avatar4.png' },
{ value:'5', name: 'modules/patients/client/img/avatar/avatar5.png' },
{ value:'6', name: 'modules/patients/client/img/avatar/avatar6.png' }
];
我想在 home.client 视图中使用头像,并且 PatientService 已经注入到 home.client 控制器中。
【问题讨论】: