AngularJS Compare
AngularJS provides a list of derivatives to provide compare with different situation .For example you can compare , a text with number to determine that the text is number or not.A text can be compare with date to determine that the text is number or not.Below is some of the directive for compare.
angular.isDate
Example
angular.isObject
AngularJS provides a list of derivatives to provide compare with different situation .For example you can compare , a text with number to determine that the text is number or not.A text can be compare with date to determine that the text is number or not.Below is some of the directive for compare.
- angular.isArray() : Check object is Array or not , Returns true if the object is an Array.
- angular.isDate() : Check object is Date or not , Returns true if the object is an Date.
- angular.isDefined() :Check object is defined or not , Returns true if the object is an defined.
- angular.isElement() :Check object is element or not , Returns true if the element is an defined.
- angular.isFunction() : Check object is function or not , Returns true if the function is an defined.
- angular.isNumber() : Check object is number or not , Returns true if the object is an number .
- angular.isObject() : Check object or not , Returns true if the object .
- angular.isString() : Check object is string or not , Returns true if the string is an number .
- angular.isUndefined() : Check object is defined or not , Returns true if the defined .
- angular.equals() : Returns true if two object are equal.
angular.isDate
Example
<div>
<!DOCTYPE
>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
</head>
<script>
var
app = angular.module("myApp",
[]);
app.controller("myController",
function
($scope)
{
$scope.date
= new
Date();
$scope.isDate
= angular.isDate($scope.date)
});
</script>
<div
style="background-color:
#F0F0F0; width:
400px;">
<div
ng-app="myApp">
<div
ng-controller="myController">
<fieldset>
<legend><b>1.Example
: isDate Directive </b></legend><span>{{isDate}}</span>
</fieldset>
</div>
</div>
</div>
</div>
Output :
true
angular.isArray
Example
<div>
<!DOCTYPE
>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
</head>
<script>
var
app = angular.module("myApp",
[]);
app.controller("myController",
function
($scope)
{
$scope.data
= ['User
1',
'User
2',
'User
3'];
$scope.isArray
= angular.isArray($scope.data)
});
</script>
<div
style="background-color:
#F0F0F0; width:
400px;">
<div
ng-app="myApp">
<div
ng-controller="myController">
<fieldset>
<legend><b>2.Example
: isArray Directive </b></legend><span>{{isArray}}</span>
</fieldset>
</div>
</div>
</div>
</div>
Output :
true
angular.isObject
Example
<div>
<!DOCTYPE
>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
</head>
<script>
var
app = angular.module("myApp",
[]);
app.controller("myController",
function
($scope)
{
$scope.data
=
{
"name":
"Ayan
Banerjee",
"Age":
"21",
"Address":
"Germany"
};
$scope.isObject
= angular.isObject($scope.data)
});
</script>
<div
style="background-color:
#F0F0F0; width:
400px;">
<div
ng-app="myApp">
<div
ng-controller="myController">
<fieldset>
<legend><b>2.Example
: isObject Directive </b></legend><span>{{isObject}}</span>
</fieldset>
</div>
</div>
</div>
</div>
Output :
true
angular.isFunction
Example
<div>
<!DOCTYPE
>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
</head>
<script>
var
app = angular.module("myApp",
[]);
app.controller("myController",
function
($scope)
{
var
myFunction = function
() { };
$scope.isFunction
= angular.isFunction(myFunction);
});
</script>
<div
style="background-color:
#F0F0F0; width:
400px;">
<div
ng-app="myApp">
<div
ng-controller="myController">
<fieldset>
<legend><b>2.Example
: isObject Directive </b></legend><span>{{isFunction}}</span>
</fieldset>
</div>
</div>
</div>
</div>
Output :
true
angular.equals
Example
<div>
<!DOCTYPE
>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
</head>
<script>
var
app = angular.module("myApp",
[]);
app.controller("myController",
function
($scope) {
var
obj1 =
{
name
: "Ayan
Banerjee",
Age
: "21",
Address:
"Germany"
}
var
obj2 =
{
name:
"Ayan
Banerjee",
Age:
"21",
Address:
"Germany"
}
$scope.isEqual=angular.equals(obj1,
obj2)
});
</script>
<div
style="background-color:
#F0F0F0; width:
400px;">
<div
ng-app="myApp">
<div
ng-controller="myController">
<fieldset>
<legend><b>2.Example
: isEqual Directive </b></legend><span>{{isEqual}}</span>
</fieldset>
</div>
</div>
</div>
</div>
Output :
true
No comments:
Post a Comment