我正在尝试连接到我们公司目前的MSSQL数据库,其中保存我们的内部门户网站。我想通过node.js做到这一点,但我目前在尝试连接数据库时遇到了问题。
下面是一个来自angular项目的app.module.ts文件的示例代码。我如何实现从这里连接到数据库?
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { ServerComponent } from './server/server.component';
import { ServersComponent } from './servers/servers.component';
@NgModule({
declarations: [
AppComponent,
ServerComponent,
ServersComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {
}
发布于 2017-09-08 22:21:02
Angular (前端)会向您的node.js服务器(后端)发出HTTP请求
然后,您的后端服务器将对您的MYSQL数据库执行它需要执行的任何调用。
服务器将对数据库结果进行任何需要的处理,然后将请求的JSON响应返回给您的Angular应用程序。
Angular本身不应该连接到任何数据库,它甚至不应该知道任何数据库。

正如评论中所建议的,您需要专注于如何从node.js访问您的数据库,例如使用mssql。
然后,您需要关注如何使用Angular服务向您的服务器发出HTTP请求。
更多信息,例如:https://scotch.io/tutorials/creating-a-single-page-todo-app-with-node-and-angular
https://stackoverflow.com/questions/46117990
复制相似问题