简体   繁体   English

未捕获的错误:无法解析AppComponent中的所有参数:(?)

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

I am doing simple user registration using Angular, Nodejs and MongoDB. 我正在使用Angular,Nodejs和MongoDB进行简单的用户注册。

I am unable to post form data from angular to Nodejs to proceed further. 我无法将表格数据从angular发布到Nodejs以便继续进行。

app.module.ts: 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: 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: 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()));
    }
}

Node (routes.js): 节点(routes.js):

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

Node server is running on 8080 port. 节点服务器在8080端口上运行。

When I am trying to post data I am getting the following error in the browser console: 当我尝试发布数据时,在浏览器控制台中出现以下错误:

Uncaught Error: Can't resolve all parameters for AppComponent: (?). 未捕获的错误:无法解析AppComponent的所有参数:(?)。

Can anyone please help to fix this issue? 谁能帮忙解决此问题? Also it will be great to know how to proceed after. 另外,知道如何进行之后将非常高兴。

You forgot to import http to your app.component . 您忘记了将http导入到app.component You have declared private http:Http in your constructor. 您已在构造函数中声明了private http:Http So add import { Http } from '@angular/http'; 因此,请import { Http } from '@angular/http';添加import { Http } from '@angular/http'; to your app.component . 到您的app.component

And use HttpClient instead of legacy Http as commented below. 并使用HttpClient代替旧版Http ,如下所述。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决“未捕获的错误:无法解析AuthService的所有参数:(?)。” - How to fix 'Uncaught Error: Can't resolve all parameters for AuthService: (?).' 错误:无法解析NoteService的所有参数:(?) - Error: Can't resolve all parameters for NoteService: (?) 无法解析ANGULAR中LoginLogin:([[Object Object],?,?)的所有参数 - Can't resolve all parameters for LoginComponent: ([object Object], ?, ?) in ANGULAR 运行时错误无法解析UserService的所有参数:(?) - Runtime error can't resolve all parameters for UserService: (?) 无法解析GlobalsService的所有参数:(?) - Can't resolve all parameters for GlobalsService: (?) 未找到模块,无法解决 Angular 中的错误 - Module not found, Can't resolve error in Angular Angular 构建 - 找不到模块:错误:无法解析“控制台” - Angular build - Module not found: Error: Can't resolve 'console' 错误:无法解析'child_process'Angular-cli - Error: Can't resolve 'child_process' Angular-cli 找不到Angular2 / 4模块:错误:无法解析“ .. \\ app”中的“三个”在解析“ .. \\ app”中的“三个” - Angular2/4 Module not found: Error: Can't resolve 'three' in '..\app' resolve 'three' in '..\app' 错误:在 Angular 13 项目中添加 libxmljs 后,无法解析“fs”和错误:无法解析“.\node_modules\bindings”中的“路径” - Error: Can't resolve 'fs' and Error: Can't resolve 'path' in '.\node_modules\bindings' after libxmljs is added in angular 13 project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM