AngularJS API用于比较, 迭代和转换对象。基本AngularJS API包括
- angular.isString()
- angular.lowercase()
- angular.uppercase()
- angular.isNumber()
1. angular.isString()
用于检查对象是否为字符串, 如果对象为字符串则返回true, 否则返回false。
例子:
<!-- Write HTML code here -->
<!DOCTYPE html>
< html >
< head >
< script src =
"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js" >
</ script >
</ head >
< body >
< div ng-app = "gfg" ng-controller = "gfgCntrl" >
< p >{{ object }}</ p >
< p >{{ apiRes }}</ p >
</ div >
< script >
var app = angular.module('gfg', []);
app.controller('gfgCntrl', function($scope) {
$scope.object = "lsbin";
$scope.apiRes = angular.isString($scope.object);
});
</ script >
</ body >
</ html >
输出如下:
2. angular.lowercase()
它用于将字符串的所有字符转换为小写字符。
例子:
<!-- Write HTML code here -->
<!DOCTYPE html>
< html >
< head >
< script src =
"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js" >
</ script >
</ head >
< body >
< div ng-app = "gfg" ng-controller = "gfgCntrl" >
< p >{{ object }}</ p >
< p >{{ apiRes }}</ p >
</ div >
< script >
var app = angular.module('gfg', []);
app.controller('gfgCntrl', function($scope) {
$scope.object = "lsbin";
$scope.apiRes = angular.lowercase($scope.object);
});
</ script >
</ body >
</ html >
输出如下:
3. angular.uppercase()
它用于将字符串的所有字符转换为大写字符。
例子:
<!-- Write HTML code here -->
<!DOCTYPE html>
< html >
< head >
< script src =
"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js" >
</ script >
</ head >
< body >
< div ng-app = "gfg" ng-controller = "gfgCntrl" >
< p >{{ object }}</ p >
< p >{{ apiRes }}</ p >
</ div >
< script >
var app = angular.module('gfg', []);
app.controller('gfgCntrl', function($scope) {
$scope.object = "lsbin";
$scope.apiRes = angular.uppercase($scope.object);
});
</ script >
</ body >
</ html >
输出如下:
4. angular.isNumber()
用于检查对象是否为数字。如果object是一个数字, 则返回true, 否则返回false。
例子:
<!-- Write HTML code here -->
<!DOCTYPE html>
< html >
< head >
< script src =
"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js" >
</ script >
</ head >
< body >
< div ng-app = "gfg" ng-controller = "gfgCntrl" >
< p >{{ object }}</ p >
< p >{{ apiRes }}</ p >
</ div >
< script >
var app = angular.module('gfg', []);
app.controller('gfgCntrl', function($scope) {
$scope.object = "lsbin";
$scope.apiRes = angular.isNumber($scope.object);
});
</ script >
</ body >
</ html >
输出如下: