AngularJS API – 8 Types of Global API’s with Examples

In this article, we will discuss What is Global API and AngularJS API functions with their examples. But, before we start this AngularJS tutorial, do you know what is API?

API (Application Programming Interface) is a software intermediary that allows two applications to communicate with each other. Every application you are using on your phone involves API. When you are using an application on your cell phone, the application first gets connected to the internet and sends data to the server. After that data is retrieved at a server and it interprets the data, performs an action to convert it into a readable format and sends the data back to the phone. This is done because of the API.

What is the AngularJS Global API?

When you are using AngularJS to implement an application, you find that there are certain tasks that you need to perform regularly such as object comparison, data conversion etc. For this purpose, you require a lot of common functionalities, which are provided by AngularJS API.

It is a set of a function of javascript. When an angular.js library is loaded then only Global APIs become available in an angularJS application.

AngularJS global API is used to perform a task such as:

  1. Comparison of objects
  2. Iteration of objects
  3. Conversion of data

To access the AngularJS global API, the object is required.

AngularJS API Function

Here, is a list of some common API function in AngularJS with examples:

1. angular.copy()

angular.copy API function is used to create a deep copy of an array of object.

  1. <!DOCTYPE html>
  2. <html>
  3. <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
  4. <body>
  5. <div ng-app="App" ng-controller="myController">
  6. <p>orignal text: {{ a }}</p>
  7. <p>result: Copied Text is {{ b }}</p>
  8. </div>
  9. <script>
  10. var t = angular.module('App', []);
  11. t.controller('myController', function($scope) {
  12. $scope.a = "Angular";
  13. $scope.b = angular.copy($scope.a);
  14. });
  15. </script>
  16. </body>
  17. </html>
No publications here.