Latest web development tutorials

AngularJS API

API意為A pplication P rogramming I nterface(應用程序編程接口)。


AngularJS 全局API

AngularJS 全局API 用於執行常見任務的JavaScript 函數集合,如:

  • 比較對象
  • 迭代對象
  • 轉換對象

全局API 函數使用angular 對象進行訪問。

以下列出了一些通用的API 函數:

API 描述
angular.lowercase() 轉換字符串為小寫
angular.uppercase() 轉換字符串為大寫
angular.isString() 判斷給定的對像是否為字符串,如果是返回true。
angular.isNumber() 判斷給定的對像是否為數字,如果是返回true。

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()

實例

< 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()

實例

< 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()

實例

< 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 >

嘗試一下»