簡體   English   中英

未捕獲的錯誤:無法解析AppComponent中的所有參數:(?)

[英]Uncaught Error: Can't resolve all parameters for AppComponent: (?) in angular

我正在使用Angular,Nodejs和MongoDB進行簡單的用戶注冊。

我無法將表格數據從angular發布到Nodejs以便繼續進行。

app.module.ts:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { HttpModule } from '@angular/http';
import { Http, Response, RequestOptions, Headers } from '@angular/http';


@NgModule({
  declarations: [
     AppComponent
  ],
   imports: [
      BrowserModule,
      FormsModule,
      ReactiveFormsModule,
      HttpModule
   ],
   providers: [Http],
   bootstrap: [AppComponent]
})

export class AppModule { }

app.component.html:

<form #registerForm="ngForm" (ngSubmit)="onSubmit(registerForm)">

<div class="form-group">
    <label for="name">Name</label>
    <input type="text" class="form-control" name="name" ngModel>
</div>

<div class="form-group">
    <label for="email">Email</label>
    <input type="email" class="form-control" name="email" ngModel>
</div>

<div class="form-group">
     <label for="password">Password</label>
     <input type="password" class="form-control" name="password" ngModel>
</div>

<div class="form-group">
      <button type="submit">Submit</button>
</div>

</form>

app.component.ts:

import { Component } from '@angular/core';
import { FormBuilder, FormGroup, Validators, FormControl, FormArray } from 
   '@angular/forms';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})

export class AppComponent {
    constructor(private http:Http) { } 
    onSubmit(registerForm) {
        console.log(registerForm.value);
        let url = 'http://localhost:8080/signup';
        this.http.post(url, {registerForm(registerForm)}).subscribe(res => 
           console.log(res.json()));
    }
}

節點(routes.js):

app.post('/signup', passport.authenticate('local-signup', {
    successRedirect : '/login', 
    failureRedirect : '/signup',
    failureFlash : true 
}));

節點服務器在8080端口上運行。

當我嘗試發布數據時,在瀏覽器控制台中出現以下錯誤:

未捕獲的錯誤:無法解析AppComponent的所有參數:(?)。

誰能幫忙解決此問題? 另外,知道如何進行之后將非常高興。

您忘記了將http導入到app.component 您已在構造函數中聲明了private http:Http 因此,請import { Http } from '@angular/http';添加import { Http } from '@angular/http'; 到您的app.component

並使用HttpClient代替舊版Http ,如下所述。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM