AngularJS API

API 表示 Application Programming Interface,即应用程序接口。


AngularJS 全局 API

AngularJS 全局 API 是一组全局 JavaScript 函数,用于执行常见任务,如:

  • Comparing 对象
  • Iterating 对象
  • Converting 数据

使用 angular 对象访问全局 API 函数。

下面是一些常见 API 函数的列表:

API描述
angular.lowercase()将字符串转换为小写
angular.uppercase()将字符串转换为大写
angular.isString()如果引用是字符串,返回
angular.isNumber()如果引用是数字,则返回 true
angular.lowercase()
实例
  1. <!DOCTYPE html>
  2. <html>
  3. <script src="https://cdn.bootcdn.net/ajax/libs/angular.js/1.8.2/angular.min.js"></script>
  4. <body>
  5. <div ng-app="myApp" ng-controller="myCtrl">
  6. <p>{{ x1 }}</p>
  7. <p>{{ x2 }}</p>
  8. </div>
  9. <script>
  10. var app = angular.module('myApp', []);
  11. app.controller('myCtrl', function($scope) {
  12. $scope.x1 = "JOHN";
  13. $scope.x2 = angular.lowercase($scope.x1);
  14. });
  15. </script>
  16. </body>
  17. </html>
angular.uppercase()
实例
  1. <!DOCTYPE html>
  2. <html>
  3. <script src="https://cdn.bootcdn.net/ajax/libs/angular.js/1.8.2/angular.min.js"></script>
  4. <body>
  5. <div ng-app="myApp" ng-controller="myCtrl">
  6. <p>{{ x1 }}</p>
  7. <p>{{ x2 }}</p>
  8. </div>
  9. <script>
  10. var app = angular.module('myApp', []);
  11. app.controller('myCtrl', function($scope) {
  12. $scope.x1 = "John";
  13. $scope.x2 = angular.uppercase($scope.x1);
  14. });
  15. </script>
  16. </body>
  17. </html>
angular.isString()
实例
  1. <!DOCTYPE html>
  2. <html>
  3. <script src="https://cdn.bootcdn.net/ajax/libs/angular.js/1.8.2/angular.min.js"></script>
  4. <body>
  5. <div ng-app="myApp" ng-controller="myCtrl">
  6. <p>{{ x1 }}</p>
  7. <p>{{ x2 }}</p>
  8. </div>
  9. <script>
  10. var app = angular.module('myApp', []);
  11. app.controller('myCtrl', function($scope) {
  12. $scope.x1 = "JOHN";
  13. $scope.x2 = angular.isString($scope.x1);
  14. });
  15. </script>
  16. </body>
  17. </html>
angular.isNumber()
实例
  1. <!DOCTYPE html>
  2. <html>
  3. <script src="https://cdn.bootcdn.net/ajax/libs/angular.js/1.8.2/angular.min.js"></script>
  4. <body>
  5. <div ng-app="myApp" ng-controller="myCtrl">
  6. <p>{{ x1 }}</p>
  7. <p>{{ x2 }}</p>
  8. </div>
  9. <script>
  10. var app = angular.module('myApp', []);
  11. app.controller('myCtrl', function($scope) {
  12. $scope.x1 = "JOHN";
  13. $scope.x2 = angular.isNumber($scope.x1);
  14. });
  15. </script>
  16. </body>
  17. </html>

分类导航