角形导入问题

时间:2020-09-30 15:28:06

标签: angular

我有以下Angular app.component.ts文件

import {NgModule} from '@angular/core';
import { Component } from '@angular/core';
@Component({
  
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
 
})
export class AppComponent {
  title = 'blog';
}

我需要在app.component.ts中导入表单模块,然后如何执行以下html文件

<h1>What is Module in Angular</h1>
<form #simpleForm="ngForm" (ngSubmit)="getValues(simpleForm.value)">
    <input type="text" ngModel name="user" placeholder="enter user name">
    <br><br>
    <input type="text" ngModel name="age" placeholder="enter user age">
    <br><br>
    <input type="text" ngModel name="address" placeholder="enter user address">
    <br><br>
    <input type="password" ngModel name="password" placeholder="enter user password">
    <br><br>
    <button>Get User Values</button>
</form>

1 个答案:

答案 0 :(得分:0)

  • Forms模块应导入到您的模块(app.module.ts)

  • 如果要使用反应形式,则必须导入“ ReactiveFormsModule” module.ts

  • 如果使用反应式表单,则需要导入验证器,FormGroup,FormControl enter image description here