错误TypeError:无法读取未定义的属性'click'

时间:2019-09-17 11:55:36

标签: javascript angular

我正在使用Angular 8应用程序,但单击事件出现错误 我有这个html:

<button mat-raised-button color="accent" (click)="saveAndPublish()" [disabled]="form.invalid">Save & Publish</button>
<button mat-raised-button color="primary" (click)="save()" [disabled]="form.invalid">Save</button>
<form [formGroup]="form">
  <app-node-tree-input formControlName="nodes"></app-node-tree-input>
</form>

这是js代码:

 constructor(
    private i18n: I18n,
    private schemaTemplateService: SchemaTemplateService,
    private blockerService: ScreenBlockerService,
    route: ActivatedRoute
  ) {
    this.schema = route.snapshot.data["schema"];
  }

  ngOnInit() {
    this.fb = new FormBuilder();
    this.form = this.fb.group({
      nodes: this.fb.control(this.schema.nodes)
    });
  }

但是我得到这个错误:

  

EditSchemaComponent.html:3错误TypeError:无法读取属性   未定义的“点击”

这是其他方法:

 save() {
    const model = this.getSubmitModel();

    if (model) {
      this.blockerService
        .blockWhileWorking(this.schemaTemplateService.createVersion(model.name, model), this.i18n("Saving..."))
        .subscribe(schema => {
          // TODO feedback
        });
    }
  }

  saveAndPublish() {
    const model = this.getSubmitModel();

    this.blockerService
      .blockWhileWorking(
        this.schemaTemplateService.createVersion(model.name, model).pipe(
          flatMap(template => {
            return this.schemaTemplateService.publish(this.schema.name, template.id);
          })
        ),
        this.i18n("Saving & Publishing...")
      )
      .subscribe(schema => {
        // TODO feedback
      });
  }
private getSubmitModel(): CreateSchemaDTO {
    if (this.form.valid) {
      const value = this.form.value;
      return {
        name: this.schema.name,
        nodes: value.nodes
      };
    }
    return null;
  }

0 个答案:

没有答案