check null,empty or undefined angularjs

前端 未结 7 378
广开言路
广开言路 2021-02-02 07:34

I am creating a project using angularjs.I have variable like

$scope.test = null
$scope.test = undefined
$scope.test = \"\"

I want to check all

相关标签:
7条回答
  • 2021-02-02 08:24

    just use -

    if(!a) // if a is negative,undefined,null,empty value then...
    {
        // do whatever
    }
    else {
        // do whatever
    }
    

    this works because of the == difference from === in javascript, which converts some values to "equal" values in other types to check for equality, as opposed for === which simply checks if the values equal. so basically the == operator know to convert the "", null, undefined to a false value. which is exactly what you need.

    0 讨论(0)
提交回复
热议问题