我正在尝试使桌面应用程序使用
electron
,
ionic4 --type-angular
npm mysql
.
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script>window.$ = window.jQuery = require('./jquery-2.1.4.js');</script>
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
<h1>Electron MySQL Example</h1>
<div id="resultDiv"></div>
<!-- All of the Node.js APIs are available in this renderer process. -->
We are using Node.js <script>document.write(process.versions.node)</script>,
Chromium <script>document.write(process.versions.chrome)</script>,
and Electron <script>document.write(process.versions.electron)</script>.
<script>
// You can also require other files to run in this process
require('./renderer.js')
</script>
<script>
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '',
database : 'electron_db'
});
connection.connect();
$sql = 'SELECT `emp_id`,`emp_name` FROM `employee`';
connection.query($sql, function (error, results, fields) {
if (error) throw error;
console.log(results);
$('#resultDiv').text(results[0].emp_name);
});
connection.end();
</script>
</body>
</html>
npm install mysql
npm install jquery
在我的项目中。我需要知道如何在我的
home.page.ts
下面是我的
主页.ts
这是错误的
ERROR in src/app/home/home.page.ts(4,18): error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try
npm i@类型/节点
.
declare var $: any;
import { Component } from '@angular/core';
var mysql = require('mysql');
var connection;
var $sql;
connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '',
database : 'electron_db'
});
connection.connect();
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
constructor(){
$sql = 'SELECT `emp_id`,`emp_name` FROM `employee`';
connection.query($sql, function (error, results, fields) {
if (error) throw error;
console.log(results);
$('#resultDiv').text(results[0].emp_name);
});
connection.end();
}
}