Advance: API

The AngularJS Global API (Application Programming Interface) is a set of global JavaScript functions for performing common tasks (comparing objects, iterating objects, converting data). They are access using Angular objects. Below is a list of some common API functions:

In the example below, the function will convert the uppercase text to lowercase:

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.normalText = "CORNELIUS";
$scope.lowerCaseText = angular.lowercase($scope.normalText);});
</script> <div ng-app="myApp" ng-controller="myCtrl">
<p>{{normalText}}</p>
<p>{{lowerCaseText}}</p> </div>
API: Uppercase Demo

NOTE: You can modify the code above to use the uppercase function with a few tweaks. Change the normalText variable value text to all lowercase letter (cornelius) and then change the method to uppercase. In the demo below, the text will be convert to uppercase.

API: Lowercase Demo


In the example below, the function will return true since the variable firstName is a string:

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.firstName = "Cornelius";
$scope.checkForString = angular.isString($scope.firstName);
});
</script> <div ng-app="myApp" ng-controller="myCtrl">
<p>{{firstName}}</p>
<p>{{checkForString}}</p>
</div>
API: ToString Demo


NOTE:
You can modify the code above to use the isNumber function with a minor tweak. Change the method to isNumber. In the demo below, the function will return fale since the variable firstName is NOT a string:

API: ToNumber Demo