我有一个控制器:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int main () {
int openedLockers[5] = {0,1,2,3,4};
return 0;
}
然后,我定义了一个用户服务。
function BenefitsController($scope, $state, Authentication, UsersService) {
//this
var vm = this;
var username = Authentication.username;
// get benefits
UsersService.listItems(function (resource, headers) {
vm.items = resource;
}
我的问题是,如何通过控制器将用户名发送到服务。这甚至是正确的做法吗?
答案 0 :(得分:2)
尝试这样的事情:
function UsersService($resource) {
var Users = $resource('/api/users', {}, {
update: {
method: 'PUT'
},
listItems: {
method: 'GET',
isArray: true,
url: '/api/users/benefits/:username',
params: {
username: '@username'
}
}
});
return Users;
}
然后您可以致电:
UsersService.listItems({username: username }, function (resource, headers) {
vm.items = resource;
},
function(err) {
// Error handling
});
jsFiddle:jsfiddle.net/gtrwzsn1/3079