在移动 View 中出现问题,在 angularjs 中没有接收到数据。 桌面 View 工作得很好......对此最好的解决方案是什么 抱歉英语不好......................................... ...................................................... ................
PHP file
<body ng-app="app" ng-controller="fcontrol">
<div ng-repeat="person in people">
{{person.fname}}
{{person.lname}}
{{person.email}}
{{person.address}}
</div>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.20/angular.min.js"></script>
<script src="js/control.js"></script>
</body>
Angularjs(control.js)
angular.module("app" , []);
function fcontrol($scope, $http) {
$http.get("http://localhost:8000/users")
.success(function(data) {
$scope.people = data;
})
}
Nodejs
app.get('/users', function(req, res) {
var s = 'SELECT * FROM tbl_user order by fname';
dbconn.query(s, function(err, rows, fields) {
var row = [];
if (err) throw err;
//console.log(rows)
res.send(rows);
res.end();
});
});
最佳答案
尝试将 Angular JS 代码中的 http get url 更改为您的 IP:8000/users。(将 localhost 替换为您的系统 IP)。 另请确保您的手机和 PC 应连接到同一网络。(如果您的 IP 不公开)
Angularjs(control.js)
angular.module("app" , []);
function fcontrol($scope, $http) {
$http.get("http://<your ip>:8000/users")
.success(function(data) {
$scope.people = data;
})
}
关于mysql - Angularjs + Nodejs + mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25445740/