switchMap无法读取未定义的值

时间:2018-08-27 15:59:10

标签: angular

我正在使用switchMap,并且出现以下错误:

  

错误TypeError:无法读取未定义的属性“ switchMap”       在StartComponent.push ../ src / app / start / start.component.ts.StartComponent.updateShortUrl中   (start.component.ts:81)       在Object.eval [作为handleEvent](StartComponent.html:19)       在handleEvent(core.js:10258)       在callWithDebugContext(core.js:11351)       在Object.debugHandleEvent [作为handleEvent](core.js:11054)       在dispatchEvent(core.js:7717)       在core.js:8161       在HTMLButtonElement。 (platform-b​​rowser.js:995)       在ZoneDelegate.push ../ node_modules / zone.js / dist / zone.js.ZoneDelegate.invokeTask   (zone.js:421)       在Object.onInvokeTask(core.js:3815)

这是怎么了?

    this.form = this.fb.group({
      first: ['', [Validators.required, Validators.pattern(this.regUrl)]],
      second: ['', [Validators.maxLength(6), Validators.pattern(this.regAlias)]],
      domainForm: [{ value: this.baseUrl, disabled: true }]
    });
  }
 this.form.value.valueChanges.switchMap(item =>
      this.urlService.update(this.data, key)
    ).subscribe((data) => {
      //this.infoUrlWasCreated();
      this.loading = false;
    });

1 个答案:

答案 0 :(得分:0)

正如克里斯蒂安在评论中所说,您正在使用未定义的订阅。根据{{​​3}},正确的使用方式是

this.form.valueChanges.subscribe(changes => {
   // ...
});