从多个表接收数据[Angular,Nodejs,MySQL]

时间:2019-05-18 09:15:06

标签: javascript html mysql node.js angular

我该怎么做才能从多个表中获取数据?

var express = require('express');
var app = express();
var mysql = require('mysql');
var connection = mysql.createConnection({
host : '',
user : '',
password : '',
database : ''
});

connection.connect(function(){
console.log("MySQL Database is Connected");
});

app.use(express.static(__dirname + '/css'));
app.use(express.static(__dirname + '/js'));

app.set('views', __dirname + '/views');
app.engine('html', require('ejs').renderFile);

app.get('/',function(req,res){

res.render('index.html');

});

app.get('/load',function(req,res){

connection.query("select * from terms WHERE status = 1",
function(err,rows,fields){
if(err) throw err;
res.end(JSON.stringify(rows));
});

});

app.listen(7001,function(){
console.log("App is started at PORT 7001");
});

js / app.js

var app = angular.module('terms', []);

js / core.js

app.controller('main_control',function($scope,$http){
load_terms();
function load_terms(){
$http.get("http://localhost:7001/load").success(function(data){
$scope.loaded_terms=data;
})
}
});

MySQL表架构

terms

|  ID | termTitle  | termStatus | 
|------|--------------|----------------|
|   1   |    hello     |        1        |
|   2   |    world   |         1        |

impTerms

|  ID   |     impTermsTitle  | termStatus | 
|-------|-----------------|----------------|
|   1   |   winter        |        1        |
|   2   |  is coming   |         1        |

角度; HTML视图:

<td>{{yaz.termTitle}}</td> // for table: "terms"


这样,我只能从terms表中获取数据。但是我需要从impTerms表中获取数据。 我怎么得到的?

谢谢

0 个答案:

没有答案