使用来自node.js的angularjs中的json数据作为后端和sql db

时间:2016-08-07 13:42:45

标签: angularjs json node.js

我正在设计一个简单的应用程序,它在后端有node.js服务器,在前面有angularjs。我正在使用这样的代码来处理从GET获取某些信息的简单sqldb请求:

req.execute('view_proc').then(function (recordsets) {
            if (recordsets) {
                res.write(JSON.stringify(recordsets));
                console.log(recordsets);
                result_send = {
                    is_logged: true,
                };

我正在使用json.stringify将数据发送到angularjs。以下是angularjs中的get请求:

$http.get('/api/views/123').success(function(data,status,headers,config){

}).
  error(function(data,status,headers,config){

});

我想知道如何在angularjs中使用JSON数据,并希望json数据以angularjs显示。

1 个答案:

答案 0 :(得分:1)

这一点都不难。从服务器接收的数据存储在回调函数内的data变量中:

$http.get('/api/views/123').success(function(data,status,headers,config){
  console.log(data)  //--> logs out the data to the console
})