Angular 2 and MySQL concepts

Are recommendations for accessing MySQL from an Angular 2 application recommended?

I am 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 (possibly with d3).

My own concept would be to implement a one-tier service that encapsulates connection calls and SQL.

But maybe I also think about the old school? Maybe there should be a different approach?

On the practical side, I don't know how to import a node-mysql package into Angular2 / Typescript - by importing the package at the top?

If someone could point me to an example, I would be happy to know.

+7
mysql angular
source share
2 answers

Communicating directly with Angular with Mysql is bad practice (in most cases). Angular runs on the client side and exposes it to mysql, allows anyone to execute SQL queries arbitrarily.

The solution is to create an inter-ministerial server. It can start nodejs, after which you can import node-mysql. The nodejs server can display the REST api that your Angular 2 application consumes.

+15
source share

Take a look at Angular-Meteor . If you were in a framework other than Meteor, you would need to start implementing a series of REST endpoints to connect the server to the client. But Meteor makes writing distributed client code as easy as talking to a local database. More in this article: https://www.angular-meteor.com/tutorials/socially/angular2/3-way-data-binding

+1
source share

All Articles