使用Nodejs搜索结果打印“未找到”

时间:2019-05-13 11:37:50

标签: javascript html node.js json nodejs-server

我使用Node.js进行MySQL即时搜索。数据作为JSON传输。 如果您在搜索结果中找不到任何内容,我想提醒您。

Server.js

var express = require('express');
var app = express();
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
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 cfg_demos",
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");
});

View.html

<script src="angular.js" type="text/javascript"></script>
<script src="app.js" type="text/javascript"></script>
<script src="core.js" type="text/javascript"></script>

&nbsp;
<div id="container">
<input id="search" size="40" type="search" placeholder="Search" />
<table id="showit">
<tbody> 
<tr>
<td>{{data.title}}</td>
<td><button id="article"><a href="{{data.link}}" target="_blank">Read Article</a></button></td>
<td><button id="demobutton"><a href="{{data.demo_link}}" target="_blank">Live Demo</a></button></td>
<td><button id="downloadbutton"><a href="{{data.download}}" target="_blank">Download</a></button></td>
</tr>
</tbody>
</table>
<div ng-if="search.length > 0"><div ng-show="!search">Not found any file</div></div>
</div>

core.js

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

如果搜索结果未找到任何内容;我正在尝试发出警告,但警告没有出现

<div ng-if="search.length > 0"><div ng-show="!search">Not found any file</div></div>

可能是什么原因?

0 个答案:

没有答案