Reputation: 9202
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?
Upvotes: 2
Views: 23638
Reputation: 1715
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
Upvotes: 1
Reputation: 2270
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.
Upvotes: 10