Angular 2和MySQL概念 [英] Angular 2 and MySQL concepts

查看:75
本文介绍了Angular 2和MySQL概念的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有推荐的概念,如何从Angular 2应用程序访问MySQL?

Are there recommended concepts how to access MySQL from an Angular 2 application?

我是Angular和Typescript的新手.我找到并安装了node-mysql软件包.我想选择一些数据集进行计算分析和一些图形表示(也许使用d3).

I'm new to Angular and Typescript. I found and installed the node-mysql package. I would like to SELECT some datasets for computational analysis and some graphical representation (perhaps with d3).

我自己的概念是实现封装连接和SQL调用的单例服务.

My own concept would be to implement a singleton service encapsulating the connection and SQL calls.

但是也许我在这里想念太老的学校了?也许应该有一种不同的方法?

But perhaps I am thinking too old school here? Perhaps there should be a different approach?

从实用的角度来看,我不确定如何在Angular2/Typescript中导入node-mysql包-通过在顶部导入该包?

On the practical side, I'm uncertain how to import the node-mysql package in Angular2 / Typescript - by importing the package at the top?

如果有人可以给我指出一个例子,我将很高兴学习.

If someone could point me to an example, I'd be glad to learn.

推荐答案

直接从Angular到Mysql进行通信是一种不好的做法(在大多数情况下). Angular运行客户端,并将mysql暴露给它允许任何人运行任意SQL语句.

Communication directly from Angular to Mysql is bad practice (in most cases). Angular runs client side and exposing mysql to it allows for anybody to run arbitrary SQL statements.

解决方案是创建一个中间服务器.它可以运行nodejs,然后可以将node-mysql导入其中. nodejs服务器可以公开Angular 2应用程序使用的REST api.

The solution is to create an intermidate server. It could run nodejs, to which you can then import node-mysql. The nodejs server could expose a REST api which your angular 2 application consumes.

这篇关于Angular 2和MySQL概念的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆