node.js - nodejs 与 angularjs 数据交互
巴扎黑
巴扎黑 2017-04-17 11:40:42
0
8
609

问大家一个问题,nodejs 与 angularjs 如何实现数据交互,如何把前台的数据通过angularjs 发送到后台,后台如何返回数据到angularjs 呢??

谢谢大家的回答,我现在不知道如何部署到服务器里,如何才能让大家访问到我的angularjs页面,呢

巴扎黑
巴扎黑

reply all(8)
迷茫

https://github.com/btford/angular-express-seed

大家讲道理

Same, it doesn’t matter whether the backend is node or not, you just need to use angular’s ​​$http service to send an ajax request; the backend will handle it. In addition, angular also supports using $resource to interact with RESTful server data sources

Ty80

It seems to be using the $http command in angulajs

洪涛

Node is on the server side and is responsible for providing API; Angular is on the client side and uses the $http service to send ajax requests and interact with the API for data

大家讲道理

XXX interacts with angularjs data

The answer should be the same

Usually use $http or $resource of angularjs to obtain

小葫芦

In fact, the main idea is to use ajax requests to process the data returned after success or failure.

In angular, you can use the $http.get() method:

$http.get().success(function(date){
    // deal data...
})
小葫芦

This problem has nothing to do with nodejs;
How to interact with data in a non-nodejs environment is the same under nodejs. It is transparent to your front end (angularjs implementation)

黄舟

I have a similar problem!
It’s no problem to get it through angular, this is pull mode!
You configure app.get render in app.js to index.html and use $http.get() to get it. I should have sent two requests!

If you bring the required data to the controller in node render, you don’t need to send an asynchronous request!

Is that so?
The following code was found online

// employeeService.queryData(function(data) {
    //   var v = _.clone(mapping.employeeList);
    //   v.list = data;

    //   console.log( v );
    //   console.log( "==============" );
    //   res.render(mapping.employeeList.view, v);
    // });
    
employeeService 是什么鬼但不到!
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template