【问题标题】:How to pass ternary value to variable in angular? [closed]如何将三元值传递给角度变量? [关闭]
【发布时间】:2020-01-19 00:30:24
【问题描述】:

对于nxsId以下this.nxsId为空时我需要传递null

public nxsId: any; // declared as any
nxsId: this.nxsId

【问题讨论】:

    标签: angular typescript angular7


    【解决方案1】:
    "nxsId": this.nxsId !== '' ? this.nxsId : null
    

    上面的语句,如果this.nxsId 为空,那么它将分配一个null 值,否则将分配一个值this.nxsId

    【讨论】:

    • 嗨,Santosh,如果 nxsId 为空,我会得到未定义的值。
    • 然后在问号之前更改条件,如果条件为真将采用 this.nxsId 的值,否则将采用空值
    猜你喜欢
    • 2016-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-17
    • 2016-02-14
    • 2023-02-13
    • 2021-01-13
    相关资源
    最近更新 更多