ng serve,ng build,ng build --prod问题

时间:2018-05-27 14:18:27

标签: angular forms ngmodel

因此ng服务和ng构建编译并运行没有错误。当我运行build prod时,它给了我Property' title'类型' {}'上不存在。我也厌倦了实现一个接口并得到相同的错误。代码运行完美,没有错误的服务。

`<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);
   }

1 个答案:

答案 0 :(得分:0)

Typescript正在寻找配方上的标题,但它们在Object类中不存在。您需要将对象的类型声明为任何类型,然后Typescript不会抱怨您的属性名称。像这样:

<强> recipe: any = {};

相关问题