如何在http.get()中传递$ scope对象来表达和获取数据。这是我的代码,任何人都可以告诉我它有什么问题吗? 因此端点网址为http://myhost:8080/employees/123。在这里,我需要从我的控制器动态传递empID到express服务器。我的代码无需传递empid即可运行并获得完整列表。
angularJs控制器
$scope.eid = "123";
$http.get('/employees/:empId=' + $scope.eid)
.success(function (data, status) {
$scope.employeeInfo = data;
}).error(function (data, status) {
});
服务器端代码
app.get("/employees/:empId", function(req,res) {
var ServerOptions = {
host: 'myHost',
port: 8000,
path: '/employees/:empId',
method: 'GET'
};
var Request = http.request(ServerOptions, function (Response) {
...
});
});
答案 0 :(得分:1)
在角度代码中你应该:
$scope.eid = "123";
$http.get('/employees/' + $scope.eid)
.success(function (data, status) {
$scope.employeeInfo = data;
}).error(function (data, status) {
});
并在快递中
app.get("/employees/:empId", function(req,res) {
var ServerOptions = {
host: 'myHost',
port: 8000,
path: '/employees/' + req.params.empId,
method: 'GET'
};
var Request = http.request(ServerOptions, function (Response) {
...
});
});