check null,empty or undefined angularjs

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

    You can do

    if($scope.test == null || $scope.test === ""){
      // null == undefined
    }
    

    if false, 0 and NaN can also be considered as false values you can just do

    if($scope.test){
     //not any of the above
    }
    

提交回复
热议问题