- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试在项目中使用 ReactiveFormsModule
。所以我将它添加到 app.module.ts
:
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { LocationStrategy,
HashLocationStrategy } from '@angular/common';
import { AppComponent } from './app.component';
import { Ng2BootstrapModule } from 'ng2-bootstrap/ng2-bootstrap';
import { NAV_DROPDOWN_DIRECTIVES } from './shared/nav-dropdown.directive';
import { ChartsModule } from 'ng2-charts/ng2-charts';
import { SIDEBAR_TOGGLE_DIRECTIVES } from './shared/sidebar.directive';
import { AsideToggleDirective } from './shared/aside.directive';
import { BreadcrumbsComponent } from './shared/breadcrumb.component';
// Routing Module
import { AppRoutingModule } from './app.routing';
//Layouts
import { FullLayoutComponent } from './layouts/full-layout.component';
import { SimpleLayoutComponent } from './layouts/simple-layout.component';
@NgModule({
imports: [
BrowserModule,
FormsModule,
ReactiveFormsModule,
AppRoutingModule,
Ng2BootstrapModule,
ChartsModule,
],
declarations: [
AppComponent,
FullLayoutComponent,
SimpleLayoutComponent,
NAV_DROPDOWN_DIRECTIVES,
BreadcrumbsComponent,
SIDEBAR_TOGGLE_DIRECTIVES,
AsideToggleDirective
],
providers: [{
provide: LocationStrategy,
useClass: HashLocationStrategy
}],
bootstrap: [ AppComponent ]
})
export class AppModule { }
这是我的组件:
import { Component, OnInit } from '@angular/core';
import { Validators, FormControl, FormGroup } from '@angular/forms';
@Component({
templateUrl: 'login.component.html'
})
export class LoginComponent implements OnInit {
loginForm: FormGroup;
constructor( ) {
this.loginForm = new FormGroup({});
}
ngOnInit(): void {
}
}
我的模板:
<div class="container d-table">
<div class="d-100vh-va-middle">
<div class="row">
<div class="col-md-8 offset-md-2">
<div class="card-group">
<div class="card p-2">
<div class="card-block">
<form [formGroup]="loginForm">
<h1>Ingreso</h1>
<p class="text-muted">Ingrese a su cuenta</p>
<div class="input-group mb-1">
<span class="input-group-addon"><i class="icon-user"></i>
</span>
<input type="text" class="form-control" placeholder="Usuario">
</div>
<div class="input-group mb-2">
<span class="input-group-addon"><i class="icon-lock"></i>
</span>
<input type="password" class="form-control" placeholder="Contraseña">
</div>
<div class="row">
<div class="col-xs-6">
<button type="button" class="btn btn-primary px-2">Ingresar</button>
</div>
<div class="col-xs-6 text-xs-right">
<button type="button" class="btn btn-link px-0">Olvidó su contraseña?</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
和 login.module.ts
:
import { NgModule } from '@angular/core';
import { LoginComponent } from './login.component';
import { LoginRoutingModule } from './login-routing.module';
@NgModule({
imports: [
LoginRoutingModule
],
declarations: [ LoginComponent ]
})
export class LoginModule { }
但我得到了众所周知的:
Can't bind to 'formGroup' since it isn't a known property of 'form'
它应该在 ReactiveFormsModule
不包含在 app.module
中时出现,但如您所见,它是导入的。我该如何解决?
最佳答案
LoginComponent
不是在提供ReactiveFormsModule
的AppModule
中声明的,它是在LoginModule
中声明的,这意味着您需要在那里导入 ReactiveFormsModule
以便在 LoginComponent
中创建响应式表单:
import { NgModule } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { LoginComponent } from './login.component';
import { LoginRoutingModule } from './login-routing.module';
@NgModule({
imports: [
ReactiveFormsModule,
LoginRoutingModule
],
declarations: [ LoginComponent ]
})
export class LoginModule { }
关于angular - 不能使用 ReactiveFormsModule,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40426638/
我在 Angular 4 中有这个主要模块: @NgModule({ imports: [ //.. other modules ReactiveFormsMo
我正在尝试在项目中使用 ReactiveFormsModule。所以我将它添加到 app.module.ts: import { NgModule }
我一直在开发我的应用程序。我想使用 ReactiveFormsModule 模块,但我得到了 Error: Unexpected module 'ReactiveFormsModule' declar
这个问题在这里已经有了答案: Angular 5 FormGroup reset doesn't reset validators (14 个答案) 关闭 4 年前。 我在下面的代码中只提交了一些详
我的 Angular 版本是这样的: Angular cli version 我创建了一个组件,它的名字是 Register我运行 ng serve whole angular project 抛出这
我正在尝试在 Angular 中创建响应式(Reactive)表单。 这是我的登录表单。 Username Password
我是 angularJS2 的新手,我正在尝试使用 ReactiveFormsModule 学习 angularJS2 表单中的验证。现在我一直在研究如何在 angularJS2 中验证单选按钮 这是
存在 ReactiveFormModule 和 FormsModule。 import { FormsModule, ReactiveFormsModule } from "@angular/
我在这里阅读了一篇写得很好的关于 Angular 模块加载的文章 - https://medium.com/@cyrilletuzi/understanding-angular-modules-ngm
我是 Angular2 的新手(昨天开始),在此之前我不是 Angular 用户。我的问题是如何以两种方式将数组绑定(bind)到 ReactiveFormsModule 中的复选框?下面是我缺失的拼
我一直在寻找这个问题的答案,每个人都说只需将 ReactiveFormsModule 添加到模块中即可解决。问题是无法识别 [formGroup]。我发现的解决方案说我只需要将导入添加到模块中,但它根
TestBed.configureTestingModule({ imports: [ FormsModule, ReactiveFormsModule,
所以我正在尝试为一个组件编写一个非常基本的测试。我只是想确保我使用 FormBuilder 创建的表单是 FormGroup 的一个实例,但我一直收到 NullInjectorerror:没有 For
在我的应用程序中,我使用 Reactive Forms 制作了一个表单。在我的应用程序中,他们是一个按钮 Add new Fields 单击此按钮添加新字段。 我可以添加新字段,但无法分配 formC
我收到此错误 - “模板解析错误:NgControl 没有提供者” The error comes from this line of code --> {{money.Curr
我刚看到这个question但我仍然有同样的错误。我有一个共享模块,我将其导入到我的功能模块中。但我也尝试过将 FormsModule、ReactiveFormsModule 模块直接导入到我的功能模
我是一名优秀的程序员,十分优秀!