typescript 如何修复此Angular 错误:参数表达式应为.ts(1135)?

kninwzqo  于 2022-12-30  发布在  TypeScript
关注(0)|答案(1)|浏览(364)

我正在学习一个粗糙的教程,一切正常,我检查了代码是否等于教程代码,但是我收到了这个错误代码预期的参数表达式。ts(1335),错误出现在提交方法onSubmit()上,我在确切的行上留下了注解,谢谢

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

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

export class AddComponent implements OnInit {

  constructor(private formBuilder: FormBuilder,
    private _studentService: StudentsService,
    private router: Router
    ) { 

  }
  addForm: FormGroup;

  ngOnInit() {

    this.addForm = this.formBuilder.group({

       fName: ['', Validators.required],
       lName: ['', [Validators.required, Validators.maxLength(9)]],
       email: ['', [Validators.required, Validators.maxLength(30)]]
    });
  }

  onSubmit() {
    //console.log(this.addForm.value);
    this._studentService.createStudent(this.addForm.value)
    .subscribe(data => {
      this.router.navigate(['view']);
    },
  } //the error it appears in this line

  }
rdrgkggo

rdrgkggo1#

试试这个:

onSubmit() {

    this._studentService.createStudent(this.addForm.value)
    .subscribe(data => {
      this.router.navigate(['view']);
    });
  }

相关问题