【发布时间】:2016-06-02 00:40:36
【问题描述】:
我正在使用 Ionic 和 MEAN 堆栈构建应用程序。我的 express 服务器在 localhost:3000 上运行,而我的 Ionic 公共代码在 localhost:8100 上运行。根据我的研究,Ionic 似乎可以在与服务器不同的 IP 地址上运行,并且应该只使用 ngResource 来发送 $http 请求。
所以我在 server.js 中有一个这样的 RESTful 端点
router.get('/', function(req, res){
res.json({"name":"Abdul"});
});
在 Ionic 客户端代码上,我发送如下请求:
app.controller('mainCtrl', function($scope, $resource){
$scope.test = $resource('localhost:3000/');
$scope.test_button = function(){
console.log($scope.test);
}
});
但是当我点击test_button,而不是[{"name":"Abdul"}] 登录控制台时,我收到以下空消息:
function Resource(value) {
shallowClearAndCopy(value || {}, this);
}
谁能帮我连接客户端和服务器?
【问题讨论】:
标签: angularjs express ionic-framework mean-stack ngresource