check null,empty or undefined angularjs

前端 未结 7 379
广开言路
广开言路 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:12

    A very simple check that you can do:

    Explanation 1:

    if (value) {
     // it will come inside
     // If value is either undefined, null or ''(empty string)
    }
    

    Explanation 2:

    (!value) ? "Case 1" : "Case 2"
    

    If the value is either undefined , null or '' then Case 1 otherwise for any other value of value Case 2.

提交回复
热议问题