Check null empty or undefined Angularjs Example
In this post we will show you Check null empty or undefined Angularjs Example, hear for Check or null or empty or undefined Angularjs Example we will give you demo and example for implement.
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.
PHP - I Can't get the $_POST Values on Ajax Request
In this post we will give you information about PHP - I Can't get the $_POST Values on Ajax Request. Hear we will give you detail about PHP - I Can't get the $_POST Values on Ajax RequestAnd how to use it also give you demo for it if it is necessary.
I want to share this posts with you because when i was working on native PHP and Ajax Post request(Specially AngularJS Post request) at that time i can't get Post value on form submit. That's why i would like to share you this post. I also want to tell you i was working on my Ubuntu 14.04. I did try lot but i can't get value.
At last find stuff to how to solve this issue, i did use "file_get_contents('php://input')" that way i could get POST value in json object and i also decode json value using "json_decode()". So let's try this way :
Example:
$post = file_get_contents('php://input');
$post = json_decode($post);
$sql = "INSERT INTO items (title) VALUES ('".$post->title."')";
$result = $mysqli->query($sql);
Hope this code and post will helped you for implement PHP - I Can't get the $_POST Values on Ajax Request. 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
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.
Check null empty or undefined Angularjs Example
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 </title>
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cscript%20src%20%3D%20%22http%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.14%2Fangular.min.js%22%3E%20%20%20%20%20%3C%2Fscript%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="<script>" title="<script>" />
</head>
<body>
<div ng-app="mainApp" ng-controller="myController">
</div>
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cscript%20type%3D%22text%2Fjavascript%22%3E%0A%09%20var%20app%20%3D%20angular.module(%22mainApp%22%2C%20%5B%5D)%3B%20%20%0A%09%20app.controller('myController'%2C%20function(%24scope%2C%20%24timeout)%20%7B%20%20%0A%09%09%20%20%24scope.myNullVar%20%3D%20null%3B%0A%09%09%20%20if%20(!%24scope.myNullVar)%20%7B%0A%09%09%09%20%20console.log('variable%20is%20a%20null.')%3B%0A%09%09%20%20%7Delse%7B%0A%09%09%09%20%20console.log('variable%20is%20a%20not%20null.')%3B%0A%09%09%20%20%7D%20%20%20%0A%09%09%20%20%24scope.myEmptyVar%20%3D%20''%3B%0A%09%09%20%20if%20(!%24scope.myNullVar)%20%7B%0A%09%09%09%20%20console.log('variable%20is%20a%20empty.')%3B%0A%09%09%20%20%7Delse%7B%0A%09%09%09%20%20console.log('variable%20is%20a%20not%20empty.')%3B%0A%09%09%20%20%7D%0A%0A%09%09%20%20if%20(!%24scope.myUndefinedVar)%20%7B%0A%09%09%09%20%20console.log('variable%20is%20a%20undefined.')%3B%0A%09%09%20%20%7Delse%7B%0A%09%09%09%20%20console.log('variable%20is%20a%20not%20undefined.')%3B%0A%09%09%20%20%7D%0A%09%20%7D)%3B%0A%20%20%20%20%20%3C%2Fscript%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="<script>" title="<script>" />
</body>
</html>
Output:
Read Also: How to get selected radio button value in AngularJS?
variable is a null. variable is a empty. variable is a undefined.
Hope this code and post will help you to implement Check 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 to help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs onlincode.org