所以 ng serve 和 ng build 编译和运行没有错误。当我运行 ng build prod 时,它给了我“{}”类型的属性“标题”不存在。我也厌倦了实现接口并得到相同的错误。该代码运行良好,ng serve 没有错误。
`<div class="row">
<div class="col-md-6">
<form #f="ngForm" (ngSubmit)="save(f.value)">
<div class="form-group">
<label for="title">Title</label>
<input #title="ngModel" [(ngModel)]="recipe.title" name="title" id="title" type="text" class="form-control" required>
<div class="alert alert-danger" *ngIf="title.touched && title.invalid">
Title is required
</div>
</div>`
这是 Ts 文件片段
export class RecipeFormComponent {
categories$: Observable<any>;
recipe = {};
id;
form = new FormGroup({
ingredients: new FormArray([])
});
constructor(
private categoryService: CategoryService,
private recipeService: RecipeService,
private router: Router,
private route: ActivatedRoute) {
this.categories$ = categoryService.getCategories();
this.id = this.route.snapshot.paramMap.get('id');
if(this.id) this.recipeService.get(this.id).take(1).subscribe(r => this.recipe = r);
}