【问题标题】:No provider for Http Angular + Node.js API没有 Http Angular + Node.js API 的提供者
【发布时间】:2018-02-10 00:01:55
【问题描述】:

我到处找,找不到我做错了什么。我正在使用 Angular 2 向我的节点服务器 api 发送一个 GET 请求,并获取它在我的名为 trade 的组件中通过数据绑定显示的信息。当我尝试查看我的 Angular 应用程序时,网络浏览器上发生错误。我的 nodejs 应用和 angular2 应用都在同一台服务器上运行。

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

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

【问题讨论】:

标签: node.js angular http provider


【解决方案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 { }

【讨论】:

    猜你喜欢
    • 2017-02-14
    • 1970-01-01
    • 2023-04-09
    • 2017-01-05
    • 2018-04-24
    • 2018-05-09
    • 2015-08-15
    • 1970-01-01
    • 2018-02-22
    相关资源
    最近更新 更多