AngularJS API
-
全局 API
AngularJS 全局API是一组用于执行常见任务的全局JavaScript函数,例如:- 比较对象
- 迭代对象
- 转换数据
全局API函数是使用 angular 对象访问的。以下是一些常见的API函数的列表:API 描述 angular.lowercase() 将字符串转换为小写 angular.uppercase() 将字符串转换为大写 angular.isString() 如果引用是字符串,则返回true angular.isNumber() 如果引用是数字,则返回true -
angular.lowercase()
下面示例演示了angular.lowercase()方法将字符串转换为小写:<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>
-
angular.uppercase()
下面示例演示了angular.uppercase()方法将字符串转换为大写:<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.uppercase($scope.x1); }); </script>
-
angular.isString()
下面示例演示了angular.isString()方法如果引用是字符串,则返回true<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>
-
angular.isNumber()
下面示例演示了angular.isNumber()方法如果引用是数字,则返回true<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>