API AngularJS
- Trang trước Xác thực AngularJS
- Trang tiếp theo Chứa AngularJS
API là viết tắt của Application Programming Interface (Giao diện lập trình ứng dụng).
AngularJS API toàn cục
AngularJS API toàn cục là bộ các hàm JavaScript toàn cục, được sử dụng để thực hiện các nhiệm vụ thông thường, chẳng hạn như:
- So sánh đối tượng
- Lặp lại đối tượng
- Chuyển đổi dữ liệu
Các hàm API toàn cục có thể truy cập thông qua đối tượng angular.
Dưới đây là danh sách các hàm API thường dùng:
API | Mô tả |
---|---|
angular.lowercase() | Chuyển đổi chuỗi thành chữ thường. |
angular.uppercase() | Chuyển đổi chuỗi thành chữ hoa. |
angular.isString() | Nếu tham chiếu là chuỗi, thì trả về true. |
angular.isNumber() | Nếu tham chiếu là số, thì trả về true. |
ngôn ngữ mẫu 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 = "BILL"; $scope.x2 = angular.lowercase($scope.x1); }); </script>
ngôn ngữ mẫu 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 = "Bill"; $scope.x2 = angular.uppercase($scope.x1); }); </script>
Mô hình angular.isString()
<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 = "BILL"; $scope.x2 = angular.isString($scope.x1); }); </script>
Mô hình angular.isNumber()
<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 = "BILL"; $scope.x2 = angular.isNumber($scope.x1); }); </script>
- Trang trước Xác thực AngularJS
- Trang tiếp theo Chứa AngularJS