我正在尝试连接到我们公司当前的MSSQL数据库,该数据库拥有我们的内部门户。我想通过node.js这样做,但我目前在尝试连接数据库时遇到问题。
以下是来自角项目的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 {
}
答案 0 :(得分:1)
Angular
(前端)会向HTTP
服务器(后端)发出node.js
次请求
然后,您的后端服务器将执行您对MYSQL
数据库所需的任何调用。
服务器将对数据库结果进行任何处理,然后将请求的JSON响应返回给Angular
应用程序。
Angular本身不应该连接到任何数据库,也不应该知道它。
根据评论中的建议,您需要关注如何从node.js
访问您的数据库,例如mssql。
然后,您需要关注如何使用Angular服务向服务器发出HTTP请求。
更多信息,例如:https://scotch.io/tutorials/creating-a-single-page-todo-app-with-node-and-angular