【发布时间】:2018-02-10 00:01:55
【问题描述】:
我到处找,找不到我做错了什么。我正在使用 Angular 2 向我的节点服务器 api 发送一个 GET 请求,并获取它在我的名为 trade 的组件中通过数据绑定显示的信息。当我尝试查看我的 Angular 应用程序时,网络浏览器上发生错误。我的 nodejs 应用和 angular2 应用都在同一台服务器上运行。
【问题讨论】:
标签: node.js angular http provider
我到处找,找不到我做错了什么。我正在使用 Angular 2 向我的节点服务器 api 发送一个 GET 请求,并获取它在我的名为 trade 的组件中通过数据绑定显示的信息。当我尝试查看我的 Angular 应用程序时,网络浏览器上发生错误。我的 nodejs 应用和 angular2 应用都在同一台服务器上运行。
【问题讨论】:
标签: node.js angular http provider
您是否已将 HttpModule 导入到您的某个 Angular 模块中?
这是我的一个例子:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpModule } from '@angular/http'; // <- HERE
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { WelcomeComponent } from './home/welcome.component';
/* Feature Modules */
import { ProductModule } from './products/product.module';
@NgModule({
imports: [
BrowserModule,
HttpModule, // <- HERE
RouterModule.forRoot([
{ path: 'welcome', component: WelcomeComponent },
{ path: '', redirectTo: 'welcome', pathMatch: 'full' },
{ path: '**', redirectTo: 'welcome', pathMatch: 'full' }
]),
ProductModule
],
declarations: [
AppComponent,
WelcomeComponent
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
【讨论】: