AngularJS API
本節(jié)為你介紹了 AngularJS 中一些通用的 API。
API 意為 Application Programming Interface(應(yīng)用程序編程接口)。
AngularJS 全局 API
AngularJS 全局 API 用于執(zhí)行常見任務(wù)的 JavaScript 函數(shù)集合,如:
- 比較對象
- 迭代對象
- 轉(zhuǎn)換對象
全局 API 函數(shù)使用 angular 對象進(jìn)行訪問。
以下列出了一些通用的 API 函數(shù):
API | 描述 |
---|---|
angular.lowercase() | 轉(zhuǎn)換字符串為小寫 |
angular.uppercase() | 轉(zhuǎn)換字符串為大寫 |
angular.isString() | 判斷給定的對象是否為字符串,如果是返回 true。 |
angular.isNumber() | 判斷給定的對象是否為數(shù)字,如果是返回 true。 |
angular.lowercase()
實(shí)例
<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>
<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()
實(shí)例
<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>
<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()
實(shí)例
<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>
<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()
實(shí)例
<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>
<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>
嘗試一下 ?
更多建議: