没有Http Angular + Node.js API的提供程序

时间:2017-08-31 23:32:47

标签: node.js angular http provider

enter image description here

我到处寻找,却找不到我做错了什么。我使用angular 2向我的节点服务器api发送GET请求,并获取在我的组件中使用数据绑定显示的信息,称为trade。当我尝试查看我的角度应用程序时,在webbrowser上发生错误。我的nodejs app和angular2 app都在同一台服务器上运行。

服务: https://hastebin.com/ileqekites.js

组件: https://hastebin.com/agopopadus.cs

1 个答案:

答案 0 :(得分:1)

你有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 { }