小编pok*_*kly的帖子

理解 TypeScript 中的问号、冒号和未定义

我对角度和打字稿很陌生,并试图了解此方法中到底发生了什么:

    updatePostcode() {
    this.FilterService.updatePostcode({

      postcode: this.regionFormGroup.get('hasPostcode').value ? 
      this.regionFormGroup.get('postcode').value : undefined

    })

    this.regionFormGroup.get('postcode').reset()
  }
Run Code Online (Sandbox Code Playgroud)

好的,这是更新邮政编码的方法。

  • 问号是什么意思?
  • “邮政编码”设置为this.regionFormGroup.get('hasPostcode').value
  • 冒号和 是什么undefined意思?( : undefined)

问题是,如果调用 updatePostcode 方法,表单将被重置,并且用户输入的邮政编码将被替换为任何内容。

syntax typescript angular

3
推荐指数
1
解决办法
6253
查看次数

标签 统计

angular ×1

syntax ×1

typescript ×1