AngularJS API

AngularJS Global API

This is made up of a group of global Javascript functions that can be used for the purpose of performing tasks such as.

  • Iterating objects
  • Comparing objects
  • Converting data

To access the global API functions, we use the angular object

Some Common API’s

Examples of common API functions are given below.



  • angular.lowercase()– used for conversion of a string into lower case.
  • angular uppercase()– used for conversion of a string to uppercase.
  • angular.isString()-the result is”true” in case the reference is a string.
  • angular isNumber()-the result is “true” if the reference is a string.

angular.lowercase() Example

Consider the example given below, which shows how a string can be converted into lowercase:

<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body>
<div ng-app="myApplication" ng-controller"myCtrl">
<p>{{p1}}</p>
<p>{{p2}}</p>
</div>
<script>
var app = angular.module('myApplication',[]);
app.controller('myCtrl', function($scope)
$scope.pl = "JOEL";
$scope.p2 = angular.lowercase($scope.p1);
});
</script>
</body>
</html>

To convert Lowercase Example Output

Just write the program as it has been written, and then run it. You will observe the following as the output:To convert Lowercase Example Output

The name has been converted from upper case to lower case as it is shown in the above figure.

angular uppercase() Example

Consider the example given below, which shows that the conversion of text to uppercase is done.

<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js></script>
<body
<div ng app "myApplication ng-controller"myCtri>
<p>{{p1}}</p>
<p>{{p2}}</p>
</div>
<script>
var app = angular.module
myApp', []);
app.controller('myCtrl', function($scope)
{
$scope.p1 = "Joel";
$scope.p2 = angular uppercase($scope.p1);
});
</script>
</body>
</html>

You can write the above program just as it has been written, and then execute it.

To convert Uppercase Example Output

The following output will be observed from it.To convert Uppercase Example Output

As shown in the above figure representing the output, the name has been converted from lowercase to uppercase. That is how it can simply be done.

angular.isString() Example

Consider the next example given below:

<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body >
<div ng-app = " myApplication"ng- controller="myCtrl">
<p>{{ p1 }}</p>
<p>{{ p2 }}</p>
</div>
<script>
var app = angular.module('myApplication', []);
app.controller('myCtrl', function($scope)
{
$scope.pl = "JOEL";
$scope.p2 = angular.isString($scope.pl);
});
</script>
</body>
</html>

In the example, we are checking whether the text which has been provided is a string or not. If it is a string, then the result should be a “true,” otherwise, it should be a “false.” After executing the above program, the following should be observed as the

Text as String Example Output

Text as String Example Output

The output given above shows that the input to the program is a string.

angular isNumber() Example

Consider the next example given below:

<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body>
<div ng-app="myApplication" ng-controller ="myCtrl">
<p>{{p1 }}</p>
<p>{{p2 }}</p>
</div>
<script>
var application = angular.module('myApplication', []);
application.controller('myCtrl', function($scope)
{
$scope.pi = "JOEL";
$scope.p2 angular.isNumber($scope.p1);
});
</script>
</body>
</html>

Text as Number Example Output

In the above case, we need to check on whether the input to the program is a number or not. When executed, the following output should be observed from it :

Text as Number Example Output

The output shows that your input is not a number.

That is how it can be done.