Simple Implementation of API (Interface) in AngularJS

  • 2021-07-06 09:46:52
  • OfStack

AngularJS API

API means Application Programming Interface (Application Programming Interface).

AngularJS Global API

AngularJS Global API A collection of JavaScript functions used to perform common tasks, such as:

Comparison object
Iterative object
Transform object

The global API function is accessed using an angular object.

Here are one of the generic API functions:

API 描述
angular.lowercase() 转换字符串为小写
angular.uppercase() 转换字符串为大写
angular.isString() 判断给定的对象是否为字符串,如果是返回 true。
angular.isNumber() 判断给定的对象是否为数字,如果是返回 true。

angular.lowercase()


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>

<div ng-app="myApp" ng-controller="myCtrl">
<p>{{ x1 }}</p>
<p>{{ x2 }}</p>
</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
 $scope.x1 = "JOHN";
 $scope.x2 = angular.lowercase($scope.x1);
});
</script>

</body>
</html>

Run results:

JOHN

john

angular.uppercase()


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>

<div ng-app="myApp" ng-controller="myCtrl">
<p>{{ x1 }}</p>
<p>{{ x2 }}</p>
</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
 $scope.x1 = "JOHN";
 $scope.x2 = angular.isString($scope.x1);
});
</script>

</body>
</html>

Run results:

JOHN

true

angular.isString()


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>

<div ng-app="myApp" ng-controller="myCtrl">
<p>{{ x1 }}</p>
<p>{{ x2 }}</p>
</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
 $scope.x1 = "JOHN";
 $scope.x2 = angular.isString($scope.x1);
});
</script>

</body>
</html>

Run results:

JOHN

true

angular.isNumber()


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>

<div ng-app="myApp" ng-controller="myCtrl">
<p>{{ x1 }}</p>
<p>{{ x2 }}</p>
</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
 $scope.x1 = "JOHN";
 $scope.x2 = angular.isNumber($scope.x1);
});
</script>

</body>
</html>

Run results:

JOHN

false

The above is the AngularJS API (interface) data collation, follow-up to continue to supplement, hoping to help programming students.


Related articles: