Check null empty or undefined Angularjs Example

Check null empty or undefined Angularjs Example

In this post we will give you information about Check null empty or undefined Angularjs Example. Hear we will give you detail about Check null empty or undefined Angularjs ExampleAnd how to use it also give you demo for it if it is necessary.

you don’t know how to check variable or object is null empty or undefined in angular js then i would like to help you to check undefined or null variable or object in angularjs. we can determine easily to variable is empty or not in angularjs.

Few months ago one developer send me email and he say me to i am working on my angularjs application and i need to check variable value is empty or null then both how can i do it. he also send me some code that he tried out. actually his code is also was working but i said him this is not way to you are checking object is empty, null or undefined in angularjs.

I said him and also send him solution that i am sharing with you. It’s very simple and easy way we can do it using code jquery logic.

So basically, you can check it as like bellow code, i also write full example so you can check and see how it works.

if (!$scope.myVar) {

// If variable is empty, null and undefined

}else{

// If not

}

Example:

<!DOCTYPE html>

<html>

<head>

<title>Check null empty or undefined Angularjs Example - ItSolutionStuff.com</title>

<script src = "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>

</head>

<body>

<div ng-app="mainApp" ng-controller="myController">

</div>

<script type="text/javascript">

var app = angular.module("mainApp", []);

app.controller('myController', function($scope, $timeout) {

$scope.myNullVar = null;

if (!$scope.myNullVar) {

console.log('variable is a null.');

}else{

console.log('variable is a not null.');

}

$scope.myEmptyVar = '';

if (!$scope.myNullVar) {

console.log('variable is a empty.');

}else{

console.log('variable is a not empty.');

}

if (!$scope.myUndefinedVar) {

console.log('variable is a undefined.');

}else{

console.log('variable is a not undefined.');

}

});

</script>

</body>

</html>

Output:

variable is a null.

variable is a empty.

variable is a undefined.

I hope it can help you…

Hope this code and post will helped you for implement Check null empty or undefined Angularjs Example. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

7  +  2  =  

We accept paid advance and paid guest Posting on our Site : Contact US