首页 > 解决方案 > 角度形式的意外 EOF 字符错误,为什么?

问题描述

我已经使用 angular 表单生成器制作了这个表单,但它在控制台中引发了错误。

错误:

compiler.js:1021 Uncaught Error: Template parse errors: Unexpected character "EOF" ("rity.value, Responsible.value)" mat-raised-button color="primary">保存

代码:

<mat-card>
  <form [formGroup]="createForm" class="create-form">
    <mat-form-field class="field-full-width">
      <input matInput placeholder="Title" formControlName="title" #title>
    </mat-form-field>
    <mat-form-field class="field-full-width">
      <input matInput placeholder="Responsible" formControlName="responsible" #responsible>
    </mat-form-field>
    <mat-form-field class="field-full-width">
        <textarea matInput placeholder="Description" formControlName="description" #description>
    </mat-form-field>
    <mat-form-field class="field-full-width">
       <mat-select placeholder="Severity" formControlName="severity" #severity>
         <mat-option value="low">Low</mat-option>
         <mat-option value="medium">Medium</mat-option>
         <mat-option value="high">High</mat-option>
       </mat-select>
    </mat-form-field>
    <mat-divider></mat-divider>
    <br>
    <br>
    <button mat-raised-button color="accent" routerLink="/list">Back</button>
    <button type="submit" (click)="addIssue(title.value, description.value, severity.value, responsible.value)" mat-raised-button color="primary">Save</button>
  </form>
</mat-card>

.ts

import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import {IssueService} from '../../../issue.service';

@Component({
  selector: 'app-create',
  templateUrl: './create.component.html',
  styleUrls: ['./create.component.css']
})
export class CreateComponent implements OnInit {

  createForm: FormGroup;

  constructor(private Issue: IssueService, private router: Router, private fb: FormBuilder) {
      this.createForm = this.fb.group({
        title: '',
        description: '',
        severity: '',
        responsible: ''
      });
  }

  addIssue(title, description, responsible, severity) {
      this.Issue.addIssue(title, description, severity, responsible).subscribe(() => {
        console.log('Issue added');
        this.router.navigate(['/list']);
      });
  }

  ngOnInit() {
  }

}

标签: angulartypescriptangular6mean-stackangular-reactive-forms

解决方案


原因是您忘记关闭textarea标签。

 <textarea ... formControlName="description" #description></textarea>
                                                             /\
                                                             ||
                                                          add this 

Angular 遵循 HTML 规范规定的相同限制


推荐阅读