What is API in Angular?
API (Application Programming Interface) in AngularJS is a set of global JavaScript functions used for the purpose of carrying out the common tasks such as comparing objects, iterating objects, converting data. Some API functions in AngularJS are as follows :
- Comparing objects
- Iterating objects
- Converting data
Watch this What is Angular 8 video:
Some API functions in AngularJS are as follows:
1. angular.lowercase
Converts the string in lowercase.
Syntax
angular.lowercase(string);
Example
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body>
<div ng-app="intellipaatApp" ng-controller="intellipaatCtrl">
<p>{{"Before Conversion: " +i1 }}</p>
<p>{{"After Conversion: " + i2 }}</p>
</div>
<script>
var app = angular.module('intellipaatApp', []);
app.controller('intellipaatCtrl', function($scope) {
$scope.i1 = "Intellipaat";
$scope.i2 = angular.lowercase($scope.i1); // convert string into lowercase
});
</script>
</body>
</html>
Output
Before Conversion: Intellipaat
After Conversion: intellipaat
2. angular.uppercase
Converts the string in uppercase.
Syntax
angular.uppercase(string);
Example
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body>
<div ng-app="intellipaatApp" ng-controller="intellipaatCtrl">
<p>{{"Before Conversion: " +i1 }}</p>
<p>{{"After Conversion: " + i2 }}</p>
</div>
<script>
var app = angular.module('intellipaatApp', []);
app.controller('intellipaatCtrl', function($scope) {
$scope.i1 = "Intellipaat";
$scope.i2 = angular.uppercase($scope.i1); // convert string into lowercase
});
</script>
</body>
</html>
Output
Before Conversion: Intellipaat
After Conversion: INTELLIPAAT
Full Stack Web Development Course Video:
3. angular.isNumber()
It checks that the given value is number or not. If value is number then it returns true otherwise returns false.
Syntax
angular.isNumber(value);
Example
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body>
<div ng-app="intellipaatApp" ng-controller="intellipaatCtrl">
<p>{{"Value is: " +i1 }}</p>
<p>{{"Value is number: " + i2 }}</p>
</div>
<script>
var app = angular.module('intellipaatApp', []);
app.controller('intellipaatCtrl', function($scope) {
$scope.i1 = 22;
$scope.i2 = angular.isNumber($scope.i1); // convert string into lowercase
});
</script>
</body>
</html>
Output
Value is: 22
Value is number: true
4. angular.isString()
It checks that the given value is string or not. If value is string then it returns true otherwise returns false.
Syntax
angular.isString(value);
Example
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body>
<div ng-app="intellipaatApp" ng-controller="intellipaatCtrl">
<p>{{"Value is: " +i1 }}</p>
<p>{{"Value is String: " + i2 }}</p>
</div>
<script>
var app = angular.module('intellipaatApp', []);
app.controller('intellipaatCtrl', function($scope) {
$scope.i1 = 22;
$scope.i2 = angular.isString($scope.i1); // convert string into lowercase
});
</script>
</body>
</html>
Output
Value is: 22
Value is String: false
Some more API is:
- isDate – Determines if a value is a date.
- isArray – Determines if a reference is anArray.
- isFunction – Determines if a reference is aFunction.
- isObject – Determines if a reference is aobject etc.