Okay! New to AngularJS. Here is my controller code to check if a value is undefined or null.
var configId=$routeParams.confiId;
angular.isUndefinedOrNull = function(configId){ return angular.isUndefined(configId) || configId === null};
if(angular.isUndefinedOrNull) {
alert(configId);
alert("true");
} else {
alert("false");
}
And it always alerts with true.
So I tried alerting configId. If the value is there, it alerts the value otherwise it is alerting undefined. Not going to else part as condition is always true. What is wrong here?
if(angular.isUndefinedOrNull) is basically checking to see if angular.isUndefinedOrNull is truthy. Since angular.isUndefinedOrNull is a function, this will always be true.
Try if( angular.isUndefinedOrNull(configId) ), which checks if the value returned by angular.isUndefinedOrNull is truthy. This will alert true if the value returned by angular.isUndefinedOrNull() is truthy, and false otherwise.
You can use basic javascript check like
if(nameOfVariable) //Returns false if variable has null or blank or undefined as value
{
}
else
{
}
Cheers from CheezyCode
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With