【发布时间】:2021-10-15 02:41:28
【问题描述】:
编辑类别组件.html:
<app-form-category *ngIf="model" [model]="model"
(onSaveChanges)="saveChanges($event)"></app-form-category>
<mat-spinner *ngIf="!model"></mat-spinner>
edit-category.component.ts
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { categoryCreationDTO, categoryDTO } from 'src/app/models/category';
import { CategoriesService } from 'src/app/services/categories.service';
@Component({
selector: 'app-edit-category',
templateUrl: './edit-category.component.html',
styleUrls: ['./edit-category.component.scss']
})
export class EditCategoryComponent implements OnInit {
constructor(
private activatedRoute: ActivatedRoute,
private categoriesService: CategoriesService,
private router: Router
) { }
model!: categoryDTO;
ngOnInit(): void {
this.activatedRoute.params.subscribe(params => {
this.categoriesService.getById(params.id).subscribe(category =>{
this.model = category;
})
});
}
saveChanges(categoryCreationDTO: categoryCreationDTO) {
this.categoriesService.edit(this.model.id, categoryCreationDTO)
.subscribe(()=>{
this.router.navigate(["/magazine"])
})
}
}
category.ts
export interface categoryCreationDTO{
name: string;
}
export interface categoryDTO{
id: number;
name: string;
}
错误
错误: src/app/components/magazine/category/edit-category/edit-category.component.html:2:30
- 错误 TS2345:“事件”类型的参数不可分配给“类别创建 DTO”类型的参数。缺少属性“名称” 在“Event”类型中,但在“categoryCreationDTO”类型中是必需的。
(onSaveChanges)="saveChanges($event)"> ~~~~~~
src/app/components/magazine/category/edit-category/edit-category.component.ts:8:16 templateUrl: './edit-category.component.html', ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 组件EditCategoryComponent的模板出错。
我不明白这个错误,有人可以帮助我吗?
【问题讨论】:
标签: html angular typescript forms