为我对这个问题的格式不正确表示歉意。我是nodejs,angularjs的新手。我正在尝试显示食品名称和价格的index.html。
我已经使用index.html下面的脚本设置了sql数据库的连接。控制台日志显示了正确的结果,但是在正文html中,我无法显示食物名称和价格。
<!doctype html>
<html>
<head>
<title>Food Stuff</title>
</head>
<body ng-app='myapp'>
<script data-main="config" src="require-2.1.22.js"></script>
<table >
<tr>
<th>Food Name</th>
<th>Food Price</th>
</tr>
<tr>
<td>{{burger}}</td> //not working
<td>{{price}}</td> //not working
</tr>
</table>
</div>
</body>
<script>
var mysql = require('mysql');
var connection = mysql.createConnection({
host: "localhost",
user: "root",
password: "password",
database : "food"
});
connection.connect((err) =>{
if (err){
return console.log(err.stack);
}
console.log("Connection established");
});
//Query start
$queryString = 'SELECT * FROM `food_item` LIMIT 10;';
connection.query($queryString, (err, results, fields)=>{
if (err){
return console.log("An error has occured", err);
}
console.log(results);
var burger = (results[0].food_name);
var price = (results[0].food_price);
});
connection.end(()=>{
console.log("Connection closed");
});
</script>
</html>
我希望html显示在localhost中
Food Name Food Price
Burger 10
但实际结果是
Food Name Food Price
{{burger}} {{price}}